class CommunityZero::Cookbook
An object representation of a cookbook.
@author Seth Vargo <sethvargo@gmail.com>
Public Class Methods
new(hash = {})
click to toggle source
Create a new cookbook from the given hash.
@param [Hash] hash
the hash from which to create the cookbook
# File lib/community_zero/objects/cookbook.rb, line 27 def initialize(hash = {}) @average_rating = 3 hash.each { |k,v| instance_variable_set(:"@#{k}",v) } end
Public Instance Methods
method_missing(m, *args, &block)
click to toggle source
# File lib/community_zero/objects/cookbook.rb, line 41 def method_missing(m, *args, &block) if m.to_s =~ /\=$/ value = args.size == 1 ? args[0] : args instance_variable_set(:"@#{m.to_s.gsub('=', '')}", value) else instance_variable_get(:"@#{m}") end end
respond_to?(m, include_private = false)
click to toggle source
# File lib/community_zero/objects/cookbook.rb, line 50 def respond_to?(m, include_private = false) instance_variables.map(&:to_s).include?("@#{m}") end
to_hash()
click to toggle source
Dump this cookbook to a hash.
@return [Hash]
the hash representation of this cookbook
# File lib/community_zero/objects/cookbook.rb, line 36 def to_hash methods = instance_variables.map { |i| i.to_s.gsub('@', '') } Hash[*methods.map { |m| [m, send(m.to_sym)] }.flatten] end