Sha256: d58ed63dbe6f3fa2d525f68e5aab9d8e9f192a8b21acbaab7bb4feb736292ee5

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 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 = ::Monetize.parse(raw_price)
      end
    end # Base
  end # Model
end # Fletcher

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fletcher-0.6.8 lib/fletcher/models/base.rb