class I18nChecker::Cache::Lines
Attributes
lines[R]
Public Class Methods
new(lines = {})
click to toggle source
# File lib/i18n_checker/cache.rb, line 70 def initialize(lines = {}) @lines = lines end
of(source)
click to toggle source
# File lib/i18n_checker/cache.rb, line 58 def of(source) lines = {} source.split("\n").each_with_index do |content, i| line_number = i + 1 lines[line_number] = Line.new(line_number, content) end last_key = lines.keys.last lines.delete last_key if lines[last_key] == '' new(lines) end
Public Instance Methods
[](scope)
click to toggle source
# File lib/i18n_checker/cache.rb, line 74 def [](scope) return lines_of(scope) if scope.is_a?(Range) return line_of(scope) if scope.is_a?(Integer) end
line_of(line_number)
click to toggle source
# File lib/i18n_checker/cache.rb, line 79 def line_of(line_number) lines[line_number] end
lines_of(range)
click to toggle source
# File lib/i18n_checker/cache.rb, line 83 def lines_of(range) results = {} raise StandardError, "invalid line number #{range.first}" if range.first <= 0 raise StandardError, "invalid line number #{range.last}" if lines.size < range.last range.each do |i| results[i] = lines[i] end self.class.new(results) end
to_s()
click to toggle source
# File lib/i18n_checker/cache.rb, line 93 def to_s lines.values.join("\n") end