Class: Representative::Base

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

Direct Known Subclasses

AbstractXml, Json

Instance Method Summary collapse

Constructor Details

#initialize(subject = nil, options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/representative/base.rb', line 7

def initialize(subject = nil, options = {})
  @subjects = [subject]
  @inspector = options[:inspector] || ObjectInspector.new
  @naming_strategy = options[:naming_strategy] || :plain
end

Instance Method Details

#current_subjectObject Also known as: subject

Return the current “subject” of representation.

This object will provide element values where they haven’t been explicitly provided.



18
19
20
# File 'lib/representative/base.rb', line 18

def current_subject
  @subjects.last
end

#representing(new_subject, &block) ⇒ Object

Evaluate a block with a specified object as #subject.



26
27
28
# File 'lib/representative/base.rb', line 26

def representing(new_subject, &block)
  with_subject(resolve_value(new_subject), &block)
end