Class: MethodMatch::Matcher
- Inherits:
-
Object
- Object
- MethodMatch::Matcher
- Defined in:
- lib/method_match/matcher.rb
Constant Summary collapse
- SPEC_MODE =
'spec'- CODE_MODE =
'code'
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
- #create_spec_name ⇒ Object
- #get_method_match ⇒ Object
-
#initialize(name, line) ⇒ Matcher
constructor
A new instance of Matcher.
- #is_spec ⇒ Object
- #method_name ⇒ Object
- #mode ⇒ Object
- #spec? ⇒ Boolean
Constructor Details
#initialize(name, line) ⇒ Matcher
Returns a new instance of Matcher.
7 8 9 10 11 |
# File 'lib/method_match/matcher.rb', line 7 def initialize name, line @name = NameExtractor.new( name ).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
#create_spec_name ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/method_match/matcher.rb', line 38 def create_spec_name @spec_name = @name.split('/') if is_spec return @spec_name = @name end @spec_name[0] = SPEC_MODE @spec_name[-1].sub!('.rb', '_spec.rb') @spec_name = @spec_name.join('/') end |
#get_method_match ⇒ Object
48 49 50 51 52 |
# File 'lib/method_match/matcher.rb', line 48 def get_method_match File.readlines(name).first(line).reverse.grep(/\sdef\s/).first rescue LoadError return nil end |
#is_spec ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/method_match/matcher.rb', line 29 def is_spec if @spec_name[0] == SPEC_MODE @mode = SPEC_MODE return true end @mode = CODE_MODE return false end |
#method_name ⇒ Object
18 19 20 21 22 23 |
# File 'lib/method_match/matcher.rb', line 18 def method_name return nil if mode == SPEC_MODE @match = get_method_match return nil unless @match @match.match(/def\s(self\.(\w+)|\w+).*/)[1] end |
#mode ⇒ Object
13 14 15 16 |
# File 'lib/method_match/matcher.rb', line 13 def mode is_spec unless @mode @mode end |
#spec? ⇒ Boolean
25 26 27 |
# File 'lib/method_match/matcher.rb', line 25 def spec? mode == SPEC_MODE end |