Class: Enumark::Item
- Inherits:
-
Object
- Object
- Enumark::Item
- Defined in:
- lib/enumark/item.rb
Constant Summary collapse
- PREFIX =
/^\s.*<DT><A/
- PATTERN =
/HREF="(.*?)".*ADD_DATE="(.*?)".*>(.*)<\/A>/
- USELESS_SHARP =
/\#.*$/
Instance Attribute Summary collapse
-
#add_date ⇒ Object
readonly
Returns the value of attribute add_date.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#dump_date ⇒ Object
readonly
Returns the value of attribute dump_date.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #categories_str ⇒ Object
- #eql?(another) ⇒ Boolean
- #hash ⇒ Object
- #host ⇒ Object
-
#initialize(dump_date, line, categories) ⇒ Item
constructor
A new instance of Item.
- #inspect ⇒ Object
- #to_s ⇒ Object
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_date ⇒ Object (readonly)
Returns the value of attribute add_date.
10 11 12 |
# File 'lib/enumark/item.rb', line 10 def add_date @add_date end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
10 11 12 |
# File 'lib/enumark/item.rb', line 10 def categories @categories end |
#dump_date ⇒ Object (readonly)
Returns the value of attribute dump_date.
10 11 12 |
# File 'lib/enumark/item.rb', line 10 def dump_date @dump_date end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
10 11 12 |
# File 'lib/enumark/item.rb', line 10 def href @href end |
#name ⇒ Object (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_str ⇒ Object
25 26 27 |
# File 'lib/enumark/item.rb', line 25 def categories_str @categories_str ||= "/#{categories.join('/')}" end |
#eql?(another) ⇒ Boolean
37 38 39 |
# File 'lib/enumark/item.rb', line 37 def eql?(another) href.eql?(another.href) end |
#hash ⇒ Object
33 34 35 |
# File 'lib/enumark/item.rb', line 33 def hash href.hash end |
#host ⇒ Object
41 42 43 |
# File 'lib/enumark/item.rb', line 41 def host @host ||= (URI.parse(href).host rescue 'unknown') end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/enumark/item.rb', line 21 def inspect @inspect ||= "#{add_date.strftime('%F %T')} #{categories_str}> #{name}" end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/enumark/item.rb', line 29 def to_s inspect end |