Class: HarvestEntry

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

Instance Method Summary collapse

Constructor Details

#initialize(parsed) ⇒ HarvestEntry

Returns a new instance of HarvestEntry.



2
3
4
# File 'lib/harvest_entry.rb', line 2

def initialize(parsed)
  @hash = parsed
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/harvest_entry.rb', line 27

def method_missing(method, *args)
  method = method.to_s.gsub("_", "-").to_sym
  
  if @hash.has_key?(method.to_s.singularize)
    entry = @hash[method.to_s.singularize]
    if method.to_s.pluralize == method.to_s && entry.class == Array
      return entry.collect {|e| HarvestEntry.new(e)}
    else
      return entry[0] unless entry[0].class == Hash && entry[0].has_key?("content")
      return entry[0]["content"]
    end
  elsif @hash.has_key?(method.to_s)
    entry = @hash[method.to_s]
    return entry[0] unless entry[0].class == Hash && entry[0].has_key?("content")
    return entry[0]["content"]
  else
    super 
  end
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/harvest_entry.rb', line 10

def empty?
  if @hash["type"] == "array" && @hash["content"] == "\n"
    true
  else
    false 
  end
end

#expense?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/harvest_entry.rb', line 18

def expense?
  begin
    self.expense_category_id
    true
  rescue
    false
  end
end

#idObject



6
7
8
# File 'lib/harvest_entry.rb', line 6

def id
  self.method_missing(:id)
end