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.



1722
1723
1724
1725
# File 'lib/sfp/sas_translator.rb', line 1722

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

Instance Method Details

#get_type(value) ⇒ Object



1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
# File 'lib/sfp/sas_translator.rb', line 1762

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



1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
# File 'lib/sfp/sas_translator.rb', line 1727

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