lib/scrapify/base.rb in scrapify-0.0.1 vs lib/scrapify/base.rb in scrapify-0.0.2

- old
+ new

@@ -1,12 +1,25 @@ module Scrapify module Base def self.included(klass) klass.extend ClassMethods klass.cattr_accessor :url, :doc, :attribute_names + klass.instance_eval { attr_reader :attributes } end + def initialize(attributes) + @attributes = attributes + end + + def method_missing(method, *args, &block) + @attributes[method] || super + end + + def to_json(*args) + @attributes.to_json(*args) + end + module ClassMethods def html(url) self.url = url define_finders end @@ -53,10 +66,10 @@ end meta_define :find_by_index do |index| return if index.nil? or index < 0 attributes = Hash[attribute_names.map {|attribute| [attribute, send("#{attribute}_values")[index]]}] - OpenStruct.new(attributes) + self.new(attributes) end end def define_count(key_attribute) meta_define :count do