Class: AmazonOrder::Parsers::Base
- Inherits:
-
Object
- Object
- AmazonOrder::Parsers::Base
- Defined in:
- lib/amazon_order/parsers/base.rb
Instance Attribute Summary collapse
-
#fetched_at ⇒ Object
Returns the value of attribute fetched_at.
Instance Method Summary collapse
- #get_original_image_url(url) ⇒ Object
-
#initialize(node, options = {}) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
- #parse_date(date_text) ⇒ Object
- #to_hash {|hash| ... } ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(node, options = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 |
# File 'lib/amazon_order/parsers/base.rb', line 6 def initialize(node, = {}) @node = node @fetched_at = [:fetched_at] @containing_object = [:containing_object] end |
Instance Attribute Details
#fetched_at ⇒ Object
Returns the value of attribute fetched_at.
4 5 6 |
# File 'lib/amazon_order/parsers/base.rb', line 4 def fetched_at @fetched_at end |
Instance Method Details
#get_original_image_url(url) ⇒ Object
38 39 40 41 |
# File 'lib/amazon_order/parsers/base.rb', line 38 def get_original_image_url(url) parts = url.split('/') (parts[0..-2] + [parts.last.split('.').values_at(0,-1).join('.')]).join('/') end |
#inspect ⇒ Object
12 13 14 |
# File 'lib/amazon_order/parsers/base.rb', line 12 def inspect "#<#{self.class.name}:#{self.object_id} #{self.to_hash}>" end |
#parse_date(date_text) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/amazon_order/parsers/base.rb', line 29 def parse_date(date_text) begin Date.parse(date_text) rescue ArgumentError => e m = date_text.match(/\A(?<year>\d{4})年(?<month>\d{1,2})月(?<day>\d{1,2})日\z/) Date.new(m[:year].to_i, m[:month].to_i, m[:day].to_i) end end |
#to_hash {|hash| ... } ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/amazon_order/parsers/base.rb', line 16 def to_hash hash = {} self.class::ATTRIBUTES.each do |f| hash[f] = send(f) end yield(hash) if block_given? hash end |
#values ⇒ Object
25 26 27 |
# File 'lib/amazon_order/parsers/base.rb', line 25 def values self.class::ATTRIBUTES.map{|a| send(a) } end |