class Wordz::Instruction

Constants

MACRO_PATTERN
METHOD_PATTERN
PROBABILITY_PATTERN

Attributes

content[R]
probability[R]

Public Class Methods

new(str) click to toggle source
# File lib/wordz/instruction.rb, line 9
def initialize(str)
  @content = extract_content(str)
  @probability = extract_probability(str)
end

Public Instance Methods

macro?() click to toggle source
# File lib/wordz/instruction.rb, line 14
def macro?
  content.match?(MACRO_PATTERN)
end
method?() click to toggle source
# File lib/wordz/instruction.rb, line 18
def method?
  content.match?(METHOD_PATTERN)
end

Private Instance Methods

extract_content(str) click to toggle source
# File lib/wordz/instruction.rb, line 32
def extract_content(str)
  prob_match_data(str) ? prob_match_data(str).pre_match : str
end
extract_probability(str) click to toggle source
# File lib/wordz/instruction.rb, line 24
def extract_probability(str)
  if prob_match_data(str)
    prob_match_data(str).captures.last.delete("|")
  else
    1
  end.to_f
end
prob_match_data(str) click to toggle source
# File lib/wordz/instruction.rb, line 36
def prob_match_data(str)
  PROBABILITY_PATTERN.match(str)
end