Class: Wishlist
- Inherits:
-
Object
- Object
- Wishlist
- Defined in:
- lib/dim_wishlist.rb
Constant Summary collapse
- WISHLIST_URI =
'https://raw.githubusercontent.com/48klocs/dim-wish-list-sources/master/choosy_voltron.txt'
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
Class Method Summary collapse
Instance Method Summary collapse
- #add_item(wishlist_item) ⇒ Object
-
#initialize(wishlist_items = []) ⇒ Wishlist
constructor
A new instance of Wishlist.
- #items_with_id(id) ⇒ Object
- #to_s ⇒ Object
- #wishlist_item?(id, perks) ⇒ Boolean
Constructor Details
#initialize(wishlist_items = []) ⇒ Wishlist
Returns a new instance of Wishlist.
43 44 45 46 |
# File 'lib/dim_wishlist.rb', line 43 def initialize(wishlist_items = []) @items = {} wishlist_items.each(&:add_item) end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
9 10 11 |
# File 'lib/dim_wishlist.rb', line 9 def items @items end |
Class Method Details
.parse(wishlist_uri = WISHLIST_URI) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dim_wishlist.rb', line 14 def parse(wishlist_uri = WISHLIST_URI) instance = self.new body = get_wishlist_text(wishlist_uri) return if body.nil? lines = [] body.split("\n").each do |line| if line =~ %r{// [a-zA-Z(]|//notes:|dimwishlist:} lines << line elsif lines.length.positive? instance.add_item(WishlistItem.new(lines)) rescue nil lines.clear end end instance end |
Instance Method Details
#add_item(wishlist_item) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/dim_wishlist.rb', line 48 def add_item(wishlist_item) wishlist_item.item_ids.each do |id| @items[id] ||= [] @items[id] << wishlist_item @items[id].uniq! end wishlist_item end |
#items_with_id(id) ⇒ Object
58 59 60 |
# File 'lib/dim_wishlist.rb', line 58 def items_with_id(id) @items[id] || [] end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/dim_wishlist.rb', line 66 def to_s @items.values.flatten.map(&:to_s).join end |
#wishlist_item?(id, perks) ⇒ Boolean
62 63 64 |
# File 'lib/dim_wishlist.rb', line 62 def wishlist_item?(id, perks) items_with_id(id).any? { |item| item.has_roll?(id, perks) } end |