Class: SVF::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/svf/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, key, cells, children = [], to = nil) ⇒ Line

Returns a new instance of Line.


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/svf/line.rb', line 5

def initialize(name, key, cells, children = [], to = nil)
  @name = name.to_sym
  @key = key
  @cells = [] # ActiveSupport::OrderedHash.new
  if cells
    cells.each do |cell|
      cell.each do |name, definition|
        unless c = Cell.new(name, definition, @key.length + @cells.inject(0) { |s, c| s += c.length })
          raise "Element #{@name} has an cell #{name} with no definition"
        end
        @cells << c
      end
    end
  end
  @children = SVF.occurrencify(children || [])
  @to = to
end

Instance Attribute Details

#cellsObject (readonly)

Returns the value of attribute cells


3
4
5
# File 'lib/svf/line.rb', line 3

def cells
  @cells
end

#childrenObject (readonly)

Returns the value of attribute children


3
4
5
# File 'lib/svf/line.rb', line 3

def children
  @children
end

#keyObject (readonly)

Returns the value of attribute key


3
4
5
# File 'lib/svf/line.rb', line 3

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/svf/line.rb', line 3

def name
  @name
end

#toObject (readonly)

Returns the value of attribute to


3
4
5
# File 'lib/svf/line.rb', line 3

def to
  @to
end

Instance Method Details

#class_name(prefix = nil) ⇒ Object


23
24
25
26
27
28
29
# File 'lib/svf/line.rb', line 23

def class_name(prefix = nil)
  if prefix.nil?
    @name.to_s.classify
  else
    "SVF::#{prefix.to_s.classify}::Lines::#{class_name}"
  end
end

#has_cells?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'lib/svf/line.rb', line 37

def has_cells?
  !@cells.size.zero?
end

#has_children?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/svf/line.rb', line 41

def has_children?
  !@children.size.zero?
end

#inspectObject


31
32
33
34
35
# File 'lib/svf/line.rb', line 31

def inspect
  i = "#{name}(#{key}) #{@cells.inspect}"
  i << "\n" + @children.collect { |c| c.inspect.gsub(/^/, '  ') }.join("\n") unless @children.empty?
  i
end