Class: Cartograph::Sculptor
- Inherits:
-
Object
- Object
- Cartograph::Sculptor
- Defined in:
- lib/cartograph/sculptor.rb
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object, map) ⇒ Sculptor
constructor
A new instance of Sculptor.
- #properties ⇒ Object
- #sculpt(scope = nil) ⇒ Object
-
#sculpted_object=(object) ⇒ Object
Set this to pass in an object to extract into.
Constructor Details
#initialize(object, map) ⇒ Sculptor
Returns a new instance of Sculptor.
5 6 7 8 |
# File 'lib/cartograph/sculptor.rb', line 5 def initialize(object, map) @object = object @map = map end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
3 4 5 |
# File 'lib/cartograph/sculptor.rb', line 3 def map @map end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/cartograph/sculptor.rb', line 3 def object @object end |
Instance Method Details
#properties ⇒ Object
10 11 12 |
# File 'lib/cartograph/sculptor.rb', line 10 def properties map.properties end |
#sculpt(scope = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cartograph/sculptor.rb', line 22 def sculpt(scope = nil) return unless @object scoped_properties = scope ? properties.filter_by_scope(scope) : properties attributes = scoped_properties.each_with_object({}) do |property, h| h[property.name] = property.value_from(object, scope) end return map.mapping.new(attributes) unless @sculpted_object attributes.each do |name, val| @sculpted_object[name] = val end @sculpted_object end |
#sculpted_object=(object) ⇒ Object
Set this to pass in an object to extract into. Must
16 17 18 19 20 |
# File 'lib/cartograph/sculptor.rb', line 16 def sculpted_object=(object) raise ArgumentError unless object.is_a?(map.mapping) @sculpted_object = object end |