Class: Sfp::SasTranslator::ValueCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/sfp/sas_translator.rb

Overview

Collects all values (primitive or non-primitive)

Instance Method Summary collapse

Constructor Details

#initialize(sas) ⇒ ValueCollector

Returns a new instance of ValueCollector.



1661
1662
1663
1664
# File 'lib/sfp/sas_translator.rb', line 1661

def initialize(sas)
  @bucket = sas.types
  @sas = sas
end

Instance Method Details

#get_type(value) ⇒ Object



1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
# File 'lib/sfp/sas_translator.rb', line 1701

def get_type(value)
  if value.is_a?(String) and not value.isref
    '$.String'
  elsif value.is_a?(Numeric)
    '$.Integer'
  elsif value.is_a?(TrueClass) or value.is_a?(FalseClass)
    '$.Boolean'
  else
    nil
  end
end

#visit(name, value, obj) ⇒ Object



1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
# File 'lib/sfp/sas_translator.rb', line 1666

def visit(name, value, obj)
  return true if name[0,1] == '_' and name != '_value'
  type = get_type(value)
  if type != nil
    @bucket[type] << value
  elsif value.is_a?(Hash)
    if value.isobject
      value['_classes'].each { |c| @bucket[c] << value }
    elsif value.isset
      raise TranslationException, 'not implemented -- set: ' + value['_isa']
    end
  elsif value.is_a?(Array)
    if value.length > 0
      type = get_type(value[0])
      if type != nil
        type = "(#{type})" # an array
        #raise Exception, "type not found: #{type}" if not @bucket.has_key?(type)
        @bucket[type] = [] if not @bucket.has_key?(type)
        @bucket["#{type}"] << value
      elsif value[0].is_a?(String) and value[0].isref
        val = @sas.root['initial'].at?(value[0])
        return true if val == nil
        type = get_type(val)
        if type != nil
          @bucket["(#{type})"] << value
        elsif val.is_a?(Hash) and val.isobject
          val['_classes'].each { |c| @bucket["(#{c})"] << value if @bucket.has_key?("(#{c})") }
        end
      end
    end
  else
  end
  return true
end