Class: Arrogance::BlogObject
- Inherits:
-
Object
- Object
- Arrogance::BlogObject
- Defined in:
- lib/arrogance/objects.rb
Instance Attribute Summary collapse
-
#aoh ⇒ Object
Returns the value of attribute aoh.
-
#data ⇒ Object
Returns the value of attribute data.
-
#positions ⇒ Object
Returns the value of attribute positions.
Instance Method Summary collapse
- #all ⇒ Object
-
#contains_positions(str) ⇒ Object
– internal methods.
- #each ⇒ Object
- #each_with_index ⇒ Object
- #feed_image ⇒ Object
- #feed_title ⇒ Object
- #get(*args) ⇒ Object
- #guts ⇒ Object
-
#initialize(array_of_hashes, data) ⇒ BlogObject
constructor
A new instance of BlogObject.
- #last ⇒ Object
- #least_recent ⇒ Object
- #method_missing(meth, *args, &block) ⇒ Object
- #most_recent ⇒ Object
- #site_link ⇒ Object
Constructor Details
#initialize(array_of_hashes, data) ⇒ BlogObject
Returns a new instance of BlogObject.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/arrogance/objects.rb', line 6 def initialize(array_of_hashes, data) @aoh, @data = array_of_hashes, data @positions = {:first => 0, :second => 1, :third => 2, :fourth => 3, :fifth => 4, :sixth => 5, :seventh => 6, :eighth => 7, :ninth => 8, :tenth => 10} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/arrogance/objects.rb', line 72 def method_missing(meth, *args, &block) if contains_positions(meth.to_s) if meth.to_s.split('_and_').length > 1 return meth.to_s.split('_and_').collect {|arg| get(arg)} else return get(meth.to_s) end else super end end |
Instance Attribute Details
#aoh ⇒ Object
Returns the value of attribute aoh.
4 5 6 |
# File 'lib/arrogance/objects.rb', line 4 def aoh @aoh end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/arrogance/objects.rb', line 4 def data @data end |
#positions ⇒ Object
Returns the value of attribute positions.
4 5 6 |
# File 'lib/arrogance/objects.rb', line 4 def positions @positions end |
Instance Method Details
#all ⇒ Object
24 25 26 |
# File 'lib/arrogance/objects.rb', line 24 def all return @aoh end |
#contains_positions(str) ⇒ Object
– internal methods. I would usually make these private, but I was once the recipient of a rant – on how private methods are Ruby’s version of Satan. I shall refrain from marking them private.
86 87 88 89 |
# File 'lib/arrogance/objects.rb', line 86 def contains_positions(str) str.split('_and_').each {|s| return false unless @positions.keys.collect {|k| k.to_s}.include?(s)} return true end |
#each ⇒ Object
28 29 30 |
# File 'lib/arrogance/objects.rb', line 28 def each @aoh.each {|e| yield e } end |
#each_with_index ⇒ Object
32 33 34 |
# File 'lib/arrogance/objects.rb', line 32 def each_with_index @aoh.each_with_index {|e, i| yield e, i} end |
#feed_image ⇒ Object
56 57 58 |
# File 'lib/arrogance/objects.rb', line 56 def feed_image return @data.feed_image end |
#feed_title ⇒ Object
48 49 50 |
# File 'lib/arrogance/objects.rb', line 48 def feed_title return @data.feed_title end |
#get(*args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/arrogance/objects.rb', line 60 def get(*args) ary = [] if args.length > 1 args.each do |pos| ary << @aoh[@positions[pos.intern]] end else return @aoh[@positions[args[0].intern]] end return ary end |
#guts ⇒ Object
20 21 22 |
# File 'lib/arrogance/objects.rb', line 20 def guts return @aoh end |
#last ⇒ Object
44 45 46 |
# File 'lib/arrogance/objects.rb', line 44 def last return least_recent end |
#least_recent ⇒ Object
40 41 42 |
# File 'lib/arrogance/objects.rb', line 40 def least_recent return @aoh[@aoh.length - 1] end |
#most_recent ⇒ Object
36 37 38 |
# File 'lib/arrogance/objects.rb', line 36 def most_recent return @aoh[0] end |
#site_link ⇒ Object
52 53 54 |
# File 'lib/arrogance/objects.rb', line 52 def site_link return @data.site_link end |