Class: LanguageTool::Resources::Matches
- Inherits:
-
Object
- Object
- LanguageTool::Resources::Matches
- Includes:
- Enumerable
- Defined in:
- lib/languagetool/resources/matches.rb
Instance Attribute Summary collapse
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#software ⇒ Object
readonly
Returns the value of attribute software.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #auto_fix ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(json) ⇒ Matches
constructor
A new instance of Matches.
- #last ⇒ Object
- #ok? ⇒ Boolean
Constructor Details
#initialize(json) ⇒ Matches
Returns a new instance of Matches.
8 9 10 11 12 13 14 15 |
# File 'lib/languagetool/resources/matches.rb', line 8 def initialize(json) super() @original = json['original'] @matches = json['matches'].map { |m| Match.new m } @software = Software.new json['software'] @language = Language.new json['language'] end |
Instance Attribute Details
#language ⇒ Object (readonly)
Returns the value of attribute language.
6 7 8 |
# File 'lib/languagetool/resources/matches.rb', line 6 def language @language end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
6 7 8 |
# File 'lib/languagetool/resources/matches.rb', line 6 def matches @matches end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
6 7 8 |
# File 'lib/languagetool/resources/matches.rb', line 6 def original @original end |
#software ⇒ Object (readonly)
Returns the value of attribute software.
6 7 8 |
# File 'lib/languagetool/resources/matches.rb', line 6 def software @software end |
Instance Method Details
#[](index) ⇒ Object
34 35 36 |
# File 'lib/languagetool/resources/matches.rb', line 34 def [](index) matches[index] end |
#auto_fix ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/languagetool/resources/matches.rb', line 21 def auto_fix str = original.clone matches.reverse.each do |match| next if match.replacements.empty? str.slice! match.offset, match.length str.insert match.offset, match.replacements.first end str end |
#each(&block) ⇒ Object
38 39 40 |
# File 'lib/languagetool/resources/matches.rb', line 38 def each(&block) matches.each(&block) end |
#last ⇒ Object
42 43 44 |
# File 'lib/languagetool/resources/matches.rb', line 42 def last matches.last end |
#ok? ⇒ Boolean
17 18 19 |
# File 'lib/languagetool/resources/matches.rb', line 17 def ok? matches.empty? end |