Class: Enumark::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/enumark/item.rb

Constant Summary collapse

PREFIX =
/^\s.*<DT><A/
PATTERN =
/HREF="(.*?)".*ADD_DATE="(.*?)".*>(.*)<\/A>/
USELESS_SHARP =
/\#.*$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dump_date, line, categories) ⇒ Item

Returns a new instance of Item.



12
13
14
15
16
17
18
19
# File 'lib/enumark/item.rb', line 12

def initialize(dump_date, line, categories)
  @dump_date = dump_date
  m = line.match(PATTERN)
  @href = m[1].gsub(USELESS_SHARP, '')
  @add_date = Time.at(m[2].to_i)
  @name = m[3]
  @categories = categories
end

Instance Attribute Details

#add_dateObject (readonly)

Returns the value of attribute add_date.



10
11
12
# File 'lib/enumark/item.rb', line 10

def add_date
  @add_date
end

#categoriesObject (readonly)

Returns the value of attribute categories.



10
11
12
# File 'lib/enumark/item.rb', line 10

def categories
  @categories
end

#dump_dateObject (readonly)

Returns the value of attribute dump_date.



10
11
12
# File 'lib/enumark/item.rb', line 10

def dump_date
  @dump_date
end

#hrefObject (readonly)

Returns the value of attribute href.



10
11
12
# File 'lib/enumark/item.rb', line 10

def href
  @href
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/enumark/item.rb', line 10

def name
  @name
end

Instance Method Details

#categories_strObject



25
26
27
# File 'lib/enumark/item.rb', line 25

def categories_str
  @categories_str ||= "/#{categories.join('/')}"
end

#eql?(another) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/enumark/item.rb', line 37

def eql?(another)
  href.eql?(another.href)
end

#hashObject



33
34
35
# File 'lib/enumark/item.rb', line 33

def hash
  href.hash
end

#hostObject



41
42
43
# File 'lib/enumark/item.rb', line 41

def host
  @host ||= (URI.parse(href).host rescue 'unknown')
end

#inspectObject



21
22
23
# File 'lib/enumark/item.rb', line 21

def inspect
  @inspect ||= "#{add_date.strftime('%F %T')} #{categories_str}> #{name}"
end

#to_sObject



29
30
31
# File 'lib/enumark/item.rb', line 29

def to_s
  inspect
end