Class: Wordz::Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/wordz/instruction.rb

Constant Summary collapse

PROBABILITY_PATTERN =
/(\|0\.[0-9]+)/
MACRO_PATTERN =
/^<.+>$/
METHOD_PATTERN =
/^\#.+\#.+\#$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Instruction

Returns a new instance of Instruction.



9
10
11
12
# File 'lib/wordz/instruction.rb', line 9

def initialize(str)
  @content = extract_content(str)
  @probability = extract_probability(str)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/wordz/instruction.rb', line 3

def content
  @content
end

#probabilityObject (readonly)

Returns the value of attribute probability.



3
4
5
# File 'lib/wordz/instruction.rb', line 3

def probability
  @probability
end

Instance Method Details

#macro?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/wordz/instruction.rb', line 14

def macro?
  content.match?(MACRO_PATTERN)
end

#method?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/wordz/instruction.rb', line 18

def method?
  content.match?(METHOD_PATTERN)
end