Class: LanguageTool::Resources::Matches

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/languagetool/resources/matches.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#languageObject (readonly)

Returns the value of attribute language.



6
7
8
# File 'lib/languagetool/resources/matches.rb', line 6

def language
  @language
end

#matchesObject (readonly)

Returns the value of attribute matches.



6
7
8
# File 'lib/languagetool/resources/matches.rb', line 6

def matches
  @matches
end

#originalObject (readonly)

Returns the value of attribute original.



6
7
8
# File 'lib/languagetool/resources/matches.rb', line 6

def original
  @original
end

#softwareObject (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_fixObject



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

#lastObject



42
43
44
# File 'lib/languagetool/resources/matches.rb', line 42

def last
  matches.last
end

#ok?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/languagetool/resources/matches.rb', line 17

def ok?
  matches.empty?
end