Class: Selene::ComponentBuilder

Inherits:
Object
  • Object
show all
Includes:
ComponentRules
Defined in:
lib/selene/component_builder.rb

Constant Summary collapse

REQUIRED_PROPERTIES =
[]
DISTINCT_PROPERTIES =
[]
EXCLUSIVE_PROPERTIES =
[]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComponentRules

#component_rules, #property_rules

Constructor Details

#initializeComponentBuilder

Returns a new instance of ComponentBuilder.



16
17
18
19
20
21
# File 'lib/selene/component_builder.rb', line 16

def initialize
  @component = Hash.new { |component, property| component[property] = [] }
  @errors = []
  @property_rules = property_rules(self)
  @component_rules = component_rules(self)
end

Instance Attribute Details

#componentObject

Returns the value of attribute component.



5
6
7
# File 'lib/selene/component_builder.rb', line 5

def component
  @component
end

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/selene/component_builder.rb', line 5

def errors
  @errors
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/selene/component_builder.rb', line 5

def parent
  @parent
end

Instance Method Details

#a_component_rulesObject



36
37
38
# File 'lib/selene/component_builder.rb', line 36

def a_component_rules
  @component_rules
end

#add(name, builder) ⇒ Object



11
12
13
14
# File 'lib/selene/component_builder.rb', line 11

def add(name, builder)
  @component[name.downcase] << builder.component
  builder.parent = self
end

#name(line) ⇒ Object



28
29
30
# File 'lib/selene/component_builder.rb', line 28

def name(line)
  line.name
end

#parse(line) ⇒ Object



23
24
25
26
# File 'lib/selene/component_builder.rb', line 23

def parse(line)
  return unless @property_rules.all? { |message, rule| rule.call(name(line), line, message) }
  @component[name(line)] = value(line)
end

#valid?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/selene/component_builder.rb', line 40

def valid?
  @component_rules.each { |message, rule| rule.call(message) }
  @errors.empty?
end

#value(line) ⇒ Object



32
33
34
# File 'lib/selene/component_builder.rb', line 32

def value(line)
  line.value
end