class ReaPack::Index::Link

Constants

REL
TAG
URL
VALID_TYPES

the first type will be the default one

Attributes

name[RW]
url[RW]

Public Class Methods

check_type(type) click to toggle source
# File lib/reapack/index/metadata.rb, line 186
def self.check_type(type)
  raise ArgumentError unless VALID_TYPES.include? type
end
find(type, search, parent) click to toggle source
# File lib/reapack/index/metadata.rb, line 206
def self.find(type, search, parent)
  Link.find_all(type, parent).find {|node|
    node.text == search || node[URL] == search
  }
end
find_all(type, parent) click to toggle source
# File lib/reapack/index/metadata.rb, line 196
def self.find_all(type, parent)
  Link.check_type type

  return [] unless parent

  parent.element_children.select {|node|
    node.name == TAG && Link.same_type?(type, node[REL].to_s.to_sym)
  }
end
from_node(node) click to toggle source
# File lib/reapack/index/metadata.rb, line 178
def self.from_node(node)
  name, url = node.text.to_s, node[URL].to_s
  url, name = name, url if url.empty?
  name = url if name.empty?

  self.new name, url
end
new(name, url) click to toggle source
# File lib/reapack/index/metadata.rb, line 212
def initialize(name, url)
  @name, @url = name, url
  @is_new = @modified = false
end
same_type?(type, user) click to toggle source
# File lib/reapack/index/metadata.rb, line 190
def self.same_type?(type, user)
  # match invalid types by the first value of VALID_TYPES
  # while the other values require an exact match
  user == type || (type == VALID_TYPES[0] && VALID_TYPES.index(user).to_i < 1)
end
split(input) click to toggle source
# File lib/reapack/index/metadata.rb, line 170
def self.split(input)
  if input =~ LINK_REGEX
    [$1, $2]
  else
    [input]
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/reapack/index/metadata.rb, line 219
def ==(other)
  name == other.name && url == other.url
end
is_new?() click to toggle source
# File lib/reapack/index/metadata.rb, line 223
def is_new?
  @is_new
end
modified?() click to toggle source
# File lib/reapack/index/metadata.rb, line 227
def modified?
  @modified
end