Class: DogShoe::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dog_shoe/base.rb

Direct Known Subclasses

Table

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/dog_shoe/base.rb', line 9

def initialize(attributes = {})
  @values = attributes[:values]
  @keys = attributes[:keys].collect{|k| k.to_sym}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



44
45
46
47
# File 'lib/dog_shoe/base.rb', line 44

def method_missing(name, *args, &block)
  super unless @keys.include? name
  @values[@keys.index(name)]
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



7
8
9
# File 'lib/dog_shoe/base.rb', line 7

def doc
  @doc
end

Class Method Details

.css(selector) ⇒ Object



27
28
29
# File 'lib/dog_shoe/base.rb', line 27

def css(selector)
  @doc.css(selector)
end

.fetch(uri) ⇒ Object



23
24
25
# File 'lib/dog_shoe/base.rb', line 23

def fetch(uri)
  open(uri)
end

.find(attrs) ⇒ Object



35
36
37
38
39
40
# File 'lib/dog_shoe/base.rb', line 35

def find(attrs)
  @doc = parse(fetch(attrs[:url]))
  results = css(attrs[:css])
  #self.class.new(results)
  results
end

.parse(body) ⇒ Object



19
20
21
# File 'lib/dog_shoe/base.rb', line 19

def parse(body)
  Nokogiri::HTML(body)
end

.valuesObject



31
32
33
# File 'lib/dog_shoe/base.rb', line 31

def values
  @values
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/dog_shoe/base.rb', line 14

def [](key)
  @values[key]
end