class Glyph::Bookmark

@since 0.4.0 This class is used to model bookmarks within a Glyph document. It contains methods to store bookmark data and resolve link paths automatically.

Attributes

definition[RW]
file[RW]
title[RW]

Public Class Methods

new(hash) click to toggle source

Initializes a bookmark object from a hash containing bookmark data. @param [Hash] hash the bookmark hash @option hash [String] :id the bookmark ID @option hash [String] :file the file containing the bookmark @option hash [String] :title the title of the bookmark @option hash [String] :definition the file where the bookmark was defined @raise [RuntimeError] if the bookmark ID is not specified @raise [RuntimeError] if the bookmark ID is invalid (it must contain only letters, numbers, - or _)

# File lib/glyph/bookmark.rb, line 20
def initialize(hash)
        @id = hash[:id].to_sym rescue nil
        @file = hash[:file]
        @title = hash[:title]
        @definition = hash[:definition]
        raise RuntimeError, "Bookmark ID not specified" unless @id
        raise RuntimeError, "Invalid bookmark ID: #{@id}" unless check_id
end

Public Instance Methods

==(b) click to toggle source

Returns true if the two bookmarks have the same ID and file @param [Glyph::Bookmark] b the bookmark to compare @raise [RuntimeError] if the parameter supplied is not a bookmark

# File lib/glyph/bookmark.rb, line 37
def ==(b)
        raise RuntimeError, "#{b.inspect} is not a bookmark" unless b.is_a? Glyph::Bookmark
        self.code == b.code && self.file == b.file
end
code() click to toggle source

Returns the bookmark ID.

# File lib/glyph/bookmark.rb, line 30
def code
        @id
end
to_s() click to toggle source

Returns the bookmark id @return [String] the bookmark ID

# File lib/glyph/bookmark.rb, line 60
def to_s
        @id.to_s
end
Also aliased as: to_str
to_str()
Alias for: to_s

Private Instance Methods

check_id() click to toggle source
# File lib/glyph/bookmark.rb, line 68
def check_id
        @id.to_s.match(/[^a-z0-9_-]/i) ? false : true
end