Class: CloudRailSi::ServiceCode::Format
- Inherits:
-
Object
- Object
- CloudRailSi::ServiceCode::Format
- Defined in:
- lib/cloudrail_si/servicecode/commands/string/Format.rb
Instance Method Summary collapse
- #execute(environment, parameters) ⇒ Object
- #get_identifier ⇒ Object
- #to_one_char_hex(element) ⇒ Object
- #to_two_char_hex(element) ⇒ Object
Instance Method Details
#execute(environment, parameters) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cloudrail_si/servicecode/commands/string/Format.rb', line 10 def execute(environment, parameters) Helper.assert(parameters.length >= 3 && Helper.is_var_address(parameters[0])) result_var = parameters[0] format = Helper.resolve(environment, parameters[1]) Helper.assert(Helper.is_string(format)) element = Helper.resolve(environment, parameters[2]) Helper.debug() if (parameters[3] == "break") res = nil case format when '%d' res = element.to_s when '%01x', '%01X' res = to_one_char_hex(element) when '%02x', '%02X' res = to_two_char_hex(element) else raise Errors::InternalError.new("Format with unsupported parameters attempted") end environment.set_variable(result_var, res) end |
#get_identifier ⇒ Object
6 7 8 |
# File 'lib/cloudrail_si/servicecode/commands/string/Format.rb', line 6 def get_identifier return 'string.format' end |
#to_one_char_hex(element) ⇒ Object
33 34 35 |
# File 'lib/cloudrail_si/servicecode/commands/string/Format.rb', line 33 def to_one_char_hex(element) ("%01x" % element).upcase end |
#to_two_char_hex(element) ⇒ Object
37 38 39 40 |
# File 'lib/cloudrail_si/servicecode/commands/string/Format.rb', line 37 def to_two_char_hex(element) # ruby-like sprintf: http://stackoverflow.com/questions/9336550/ruby-sprintf-about-the-2-in-02x ("%02x" % element).upcase end |