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.



1749
1750
1751
1752
# File 'lib/sfp/sas_translator.rb', line 1749

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

Instance Method Details

#get_type(value) ⇒ Object



1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
# File 'lib/sfp/sas_translator.rb', line 1789

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



1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
# File 'lib/sfp/sas_translator.rb', line 1754

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