Class: MethodMatch::Matcher
- Inherits:
-
Object
- Object
- MethodMatch::Matcher
- Defined in:
- lib/method_match/matcher.rb
Constant Summary collapse
- SPEC_MODE =
'spec'
- CODE_MODE =
'code'
- RUBY_FILETYPE =
".rb"
- SPEC_FILE_ENDING =
'_spec.rb'
- METHOD_NAME_REGEX =
/def\s(self\.(\w+)|\w+).*/
Instance Attribute Summary collapse
-
#line ⇒ Object
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
-
#spec_name ⇒ Object
Returns the value of attribute spec_name.
Instance Method Summary collapse
- #convert_code_to_spec(name) ⇒ Object
- #create_spec_name ⇒ Object
- #get_method_match ⇒ Object
-
#initialize(name, line) ⇒ Matcher
constructor
A new instance of Matcher.
- #method_name ⇒ Object
- #mode ⇒ Object
- #spec? ⇒ Boolean
Constructor Details
#initialize(name, line) ⇒ Matcher
Returns a new instance of Matcher.
10 11 12 13 14 |
# File 'lib/method_match/matcher.rb', line 10 def initialize name, line @name = NameExtractor.new( name ).final_name @line = line create_spec_name end |
Instance Attribute Details
#line ⇒ Object
Returns the value of attribute line.
3 4 5 |
# File 'lib/method_match/matcher.rb', line 3 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/method_match/matcher.rb', line 3 def name @name end |
#spec_name ⇒ Object
Returns the value of attribute spec_name.
3 4 5 |
# File 'lib/method_match/matcher.rb', line 3 def spec_name @spec_name end |
Instance Method Details
#convert_code_to_spec(name) ⇒ Object
41 42 43 44 45 |
# File 'lib/method_match/matcher.rb', line 41 def convert_code_to_spec name name[0] = SPEC_MODE name.last.sub!(RUBY_FILETYPE, SPEC_FILE_ENDING) name.join File::SEPARATOR end |
#create_spec_name ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/method_match/matcher.rb', line 32 def create_spec_name @spec_name = name.split(File::SEPARATOR) @spec_name = if spec? name else convert_code_to_spec name.split(File::SEPARATOR) end end |
#get_method_match ⇒ Object
47 48 49 50 51 |
# File 'lib/method_match/matcher.rb', line 47 def get_method_match File.readlines(name).first(line).reverse.grep(METHOD_NAME_REGEX).first rescue LoadError return nil end |
#method_name ⇒ Object
21 22 23 24 25 26 |
# File 'lib/method_match/matcher.rb', line 21 def method_name return nil if spec? @match = get_method_match return nil unless @match @match.match(METHOD_NAME_REGEX)[1] end |
#mode ⇒ Object
16 17 18 19 |
# File 'lib/method_match/matcher.rb', line 16 def mode set_mode unless @mode @mode end |
#spec? ⇒ Boolean
28 29 30 |
# File 'lib/method_match/matcher.rb', line 28 def spec? mode == SPEC_MODE end |