class Tradesman::Parser

Constants

PARSE_REGEX
PARSE_REGEX_WITH_PARENT

Attributes

action_string[R]
class_name[R]
parent_string[R]
subject_string[R]

Public Class Methods

new(class_name) click to toggle source
# File lib/tradesman/parser.rb, line 8
def initialize(class_name)
  @class_name = class_name
  @match = class_name.to_s.match(regex)
  @action_string, @subject_string, @parent_string = @match.values_at(1, 2, 3) if @match
end

Public Instance Methods

action() click to toggle source
# File lib/tradesman/parser.rb, line 18
def action
  str_to_sym(@action_string)
end
match?() click to toggle source
# File lib/tradesman/parser.rb, line 14
def match?
  !!@match
end
parent() click to toggle source
# File lib/tradesman/parser.rb, line 26
def parent
  return nil unless @parent_string
  str_to_sym(@parent_string)
end
subject() click to toggle source
# File lib/tradesman/parser.rb, line 22
def subject
  str_to_sym(@subject_string)
end

Private Instance Methods

regex() click to toggle source
# File lib/tradesman/parser.rb, line 33
def regex
  /.+For[A-Z]+.+/.match(@class_name) ? PARSE_REGEX_WITH_PARENT : PARSE_REGEX
end
str_to_sym(str) click to toggle source
# File lib/tradesman/parser.rb, line 37
def str_to_sym(str)
  str.underscore.symbolize
end