Class: Kartograph::Sculptor
- Inherits:
-
Object
- Object
- Kartograph::Sculptor
- Defined in:
- lib/kartograph/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
-
#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/kartograph/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/kartograph/sculptor.rb', line 3 def map @map end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/kartograph/sculptor.rb', line 3 def object @object end |
Instance Method Details
#properties ⇒ Object
10 11 12 |
# File 'lib/kartograph/sculptor.rb', line 10 def properties map.properties end |
#sculpt(scope = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kartograph/sculptor.rb', line 27 def sculpt(scope = nil) return nil if @object.nil? scoped_properties = scope ? properties.filter_by_scope(scope) : properties scoped_properties.each_with_object(sculpted_object) do |property, mutable| setter_method = "#{property.name}=" value = property.value_from(object, scope) mutable.send(setter_method, value) end end |
#sculpted_object ⇒ Object
14 15 16 17 |
# File 'lib/kartograph/sculptor.rb', line 14 def sculpted_object # Fallback initialization of the object we're extracting into @sculpted_object ||= map.mapping.new end |
#sculpted_object=(object) ⇒ Object
Set this to pass in an object to extract into. Must
21 22 23 24 25 |
# File 'lib/kartograph/sculptor.rb', line 21 def sculpted_object=(object) raise ArgumentError unless object.is_a?(map.mapping) @sculpted_object = object end |