Sha256: 83dff2daf6c9ade03b4fed42a69831d11dfe7aca1f73cb7caf7953656ca1404a

Contents?: true

Size: 768 Bytes

Versions: 4

Compression:

Stored size: 768 Bytes

Contents

require "hashie"
require "money"

module Fletcher
  module Model
    class Base < ::Hashie::Mash         
      # Parse data and set object attributes    
      def parse(data)
        self.doc = data # save data for if user wants to access it later      

        # Get page title as name
        self.name = doc.css("head > title").first_string
      end      

      # Parse a raw price string to get usable data
      #   model.parse_price("$5.00") # => #<Money cents:500 currency:USD>
      #   model.price.to_f # => 5.0
      #   model.price.currency.symbol # => '$'
      def parse_price(raw_price = nil)
        return if raw_price.nil?
        self.price = ::Money.parse(raw_price)
      end
    end # Base
  end # Model
end # Fletcher

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fletcher-0.6.6 lib/fletcher/models/base.rb
fletcher-0.6.5 lib/fletcher/models/base.rb
fletcher-0.6.4 lib/fletcher/models/base.rb
fletcher-0.6.2 lib/fletcher/models/base.rb