Class: SentenceBuilder::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/sentence_builder/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodes = []) ⇒ Builder

Returns a new instance of Builder.



8
9
10
# File 'lib/sentence_builder/builder.rb', line 8

def initialize(nodes = [])
  @nodes = nodes.select{|b| b.is_a?(SentenceNode)}
end

Instance Method Details

#get_hash(params = {}, sorted = true) ⇒ Object

Return all nodes in order as an hashalways_use



13
14
15
# File 'lib/sentence_builder/builder.rb', line 13

def get_hash(params = {}, sorted = true)
  get_nodes(sorted).map{|n| n.to_hash(params[n.name])}
end

#get_sentence(params = {}, sorted = true, separator = ' ') ⇒ Object

 Returns the string representation of nodes and blocks by updating with given parameters



18
19
20
# File 'lib/sentence_builder/builder.rb', line 18

def get_sentence(params = {}, sorted = true, separator = ' ')
  build_sentence_from_hash(get_hash(params, sorted)).select(&:present?).join(separator)
end