Module: Rips::Utils::StringAssemblerExtension
- Included in:
- String
- Defined in:
- lib/rips/utils/string_assembler.rb
Instance Method Summary collapse
-
#arg_to_i ⇒ Object
Return integer part of arguments of an instruction.
-
#comment? ⇒ Boolean
Check if string is a comment.
-
#del(regexp) ⇒ Object
Delete spaces and tabs.
-
#del!(regexp) ⇒ Object
Delete spaces and tabs.
-
#instruction? ⇒ Boolean
Check if string is a instruction.
-
#instruction_arguments(instruction) ⇒ Object
Get intruction’s arguments of string.
-
#instruction_comments ⇒ Object
Get intruction’s comments of string.
-
#instruction_name ⇒ Object
Get intruction’s name of string.
-
#label?(line) ⇒ Boolean
Check if string is a label.
Instance Method Details
#arg_to_i ⇒ Object
Return integer part of arguments of an instruction
18 19 20 |
# File 'lib/rips/utils/string_assembler.rb', line 18 def arg_to_i (/\A[-]?\d+\z/ === self) ? self.to_i : self.slice(1..-1).to_i end |
#comment? ⇒ Boolean
Check if string is a comment
23 24 25 |
# File 'lib/rips/utils/string_assembler.rb', line 23 def comment? self[0] == "#" end |
#del(regexp) ⇒ Object
Delete spaces and tabs
8 9 10 |
# File 'lib/rips/utils/string_assembler.rb', line 8 def del(regexp) gsub(regexp,'') end |
#del!(regexp) ⇒ Object
Delete spaces and tabs
13 14 15 |
# File 'lib/rips/utils/string_assembler.rb', line 13 def del!(regexp) gsub!(regexp,'') end |
#instruction? ⇒ Boolean
Check if string is a instruction
40 41 42 |
# File 'lib/rips/utils/string_assembler.rb', line 40 def instruction? (!self.empty?) && (self[0] != "#") && (self.scan(/\w+:/).empty?) end |
#instruction_arguments(instruction) ⇒ Object
Get intruction’s arguments of string
50 51 52 53 |
# File 'lib/rips/utils/string_assembler.rb', line 50 def instruction_arguments(instruction) args = self.split("#").first.split("#{instruction} ") args.pop.split("#").first.del(/\s+|\t+/).split(",") unless args.empty? end |
#instruction_comments ⇒ Object
Get intruction’s comments of string
56 57 58 |
# File 'lib/rips/utils/string_assembler.rb', line 56 def instruction_comments self.split("#").slice(1..-1).join end |
#instruction_name ⇒ Object
Get intruction’s name of string
45 46 47 |
# File 'lib/rips/utils/string_assembler.rb', line 45 def instruction_name self.split("#").first.split(" ").first.downcase end |
#label?(line) ⇒ Boolean
Check if string is a label
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rips/utils/string_assembler.rb', line 28 def label?(line) if (!self.empty?) && (self[0] != "#") && (self[-1] == ":") label = self.scan(/\w+:/) if (label.size == 1) return true elsif (label.size > 1) Error::(8, line+1, self) end end end |