Class: Get::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/get/parser.rb

Constant Summary collapse

CLASS_REGEX =
/^(.*)(By|From|JoinedWith)(.*)/
CLASS_NAME_BY_ERROR =
'You have multiple instances of "By" in your class. Please use open-ended form ie. Get::UserBy.run(params)'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name) ⇒ Parser

Returns a new instance of Parser.


7
8
9
10
11
12
13
# File 'lib/get/parser.rb', line 7

def initialize(class_name)
  raise Get::Errors::InvalidClassName.new(CLASS_NAME_BY_ERROR) if class_name.to_s.split('By').length > 2

  @class_name = class_name
  @match = class_name.to_s.match(CLASS_REGEX)
  @result_entity, @method, @key_string = @match.values_at(1, 2, 3) if @match
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.


5
6
7
# File 'lib/get/parser.rb', line 5

def class_name
  @class_name
end

#methodObject

Returns the value of attribute method.


5
6
7
# File 'lib/get/parser.rb', line 5

def method
  @method
end

#result_entityObject

Returns the value of attribute result_entity.


5
6
7
# File 'lib/get/parser.rb', line 5

def result_entity
  @result_entity
end

Instance Method Details

#keyObject


19
20
21
# File 'lib/get/parser.rb', line 19

def key
  @key_string.present? ? @key_string.symbolize : nil
end

#match?Boolean

Returns:

  • (Boolean)

15
16
17
# File 'lib/get/parser.rb', line 15

def match?
  !!@match
end