Class: Mingle::Card
- Inherits:
-
Object
- Object
- Mingle::Card
- Defined in:
- lib/mingle/card.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
Class Method Summary collapse
Instance Method Summary collapse
- #attachments ⇒ Object
-
#initialize(xml) ⇒ Card
constructor
A new instance of Card.
- #save! ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(xml) ⇒ Card
Returns a new instance of Card.
42 43 44 45 46 47 |
# File 'lib/mingle/card.rb', line 42 def initialize(xml) document = Nokogiri::XML.parse(xml) @description = document.xpath('./card/description').text @number = document.xpath('./card/number').text.to_i @name = document.xpath('./card/name').text end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
40 41 42 |
# File 'lib/mingle/card.rb', line 40 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
40 41 42 |
# File 'lib/mingle/card.rb', line 40 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
40 41 42 |
# File 'lib/mingle/card.rb', line 40 def number @number end |
Class Method Details
.all(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mingle/card.rb', line 7 def self.all(={}) = {starting_from: '1'}.merge() Logging.debug "Mingle API => #{@@api.inspect}" starting_card_number = [:starting_with].to_i max_card_number = unless [:limit] mql = "SELECT MAX(number)" results = @@api.execute_mql(mql) Logging.debug "#{mql}: #{results.inspect}" results[0]['max_number'].to_i else starting_card_number + [:limit].to_i end Enumerator.new do |yielder| (starting_card_number..max_card_number).to_a.each do |number| begin yielder.yield Card.find_by_number(number) rescue => e Logging.error "Unable to fetch card ##{number} due to #{e.}" end end end end |
.api=(api) ⇒ Object
36 37 38 |
# File 'lib/mingle/card.rb', line 36 def self.api=(api) @@api = api end |
Instance Method Details
#attachments ⇒ Object
53 54 55 |
# File 'lib/mingle/card.rb', line 53 def @attachments ||= Attachment.find_all_by_card_number(number) end |
#save! ⇒ Object
57 58 59 |
# File 'lib/mingle/card.rb', line 57 def save! @@api.save_card(self) end |
#to_xml ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/mingle/card.rb', line 61 def to_xml Nokogiri::XML::Builder.new { |xml| xml.card { xml.description(@description) } }.to_xml end |