Class: HatebuEntry::Entry
- Inherits:
-
Struct
- Object
- Struct
- HatebuEntry::Entry
- Defined in:
- lib/hatebu_entry.rb
Overview
link: uri string count: integer title: string
Defined Under Namespace
Classes: MergeError
Instance Attribute Summary collapse
-
#count ⇒ Object
(also: #bookmarks)
Returns the value of attribute count.
-
#link ⇒ Object
(also: #url)
Returns the value of attribute link.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.merge(ls_a, ls_b) ⇒ Object
Merge two entry lists.
Instance Method Summary collapse
- #date ⇒ Object
-
#homogeneous?(other) ⇒ Boolean
(also: #same?)
to find same entry but other hosts.
-
#merge(other) ⇒ Object
Merge its count.
- #to_s ⇒ Object
Instance Attribute Details
#count ⇒ Object Also known as: bookmarks
Returns the value of attribute count
14 15 16 |
# File 'lib/hatebu_entry.rb', line 14 def count @count end |
#link ⇒ Object Also known as: url
Returns the value of attribute link
14 15 16 |
# File 'lib/hatebu_entry.rb', line 14 def link @link end |
#title ⇒ Object
Returns the value of attribute title
14 15 16 |
# File 'lib/hatebu_entry.rb', line 14 def title @title end |
Class Method Details
.merge(ls_a, ls_b) ⇒ Object
Merge two entry lists
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hatebu_entry.rb', line 55 def self.merge(ls_a, ls_b) if [ls_a, ls_b].all? { |ls| ls.is_a? Entry } raise ArgumentError, 'Arguments must be entry objects' end entries = [] ls_a.each do |a| if m = ls_b.detect { |b| a.homogeneous? b } entries.push a.merge(m) ls_b.delete(m) else entries.push a end end entries + ls_b end |
Instance Method Details
#date ⇒ Object
17 18 19 20 21 |
# File 'lib/hatebu_entry.rb', line 17 def date @date ||= Date.parse(link) rescue ArgumentError nil end |
#homogeneous?(other) ⇒ Boolean Also known as: same?
to find same entry but other hosts
28 29 30 31 32 33 |
# File 'lib/hatebu_entry.rb', line 28 def homogeneous?(other) return false if self == other return nil if [self, other].any? { |e| e.date.nil? } self.date == other.date && title_similar?(self.title, other.title) end |
#merge(other) ⇒ Object
Merge its count
45 46 47 48 49 50 51 52 |
# File 'lib/hatebu_entry.rb', line 45 def merge(other) count = self.count + other.count if block_given? && !yield(self, other) raise MergeError, "They can't merge" else Entry.new(self.link, count, self.title) end end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/hatebu_entry.rb', line 23 def to_s "%5d: %s (%s)" % [count, title, link] end |