Class: I18nChecker::Cache::Lines
- Inherits:
-
Object
- Object
- I18nChecker::Cache::Lines
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/i18n_checker/cache.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Class Method Summary collapse
Instance Method Summary collapse
- #[](scope) ⇒ Object
-
#initialize(lines = {}) ⇒ Lines
constructor
A new instance of Lines.
- #line_of(line_number) ⇒ Object
- #lines_of(range) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(lines = {}) ⇒ Lines
Returns a new instance of Lines.
70 71 72 |
# File 'lib/i18n_checker/cache.rb', line 70 def initialize(lines = {}) @lines = lines end |
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
53 54 55 |
# File 'lib/i18n_checker/cache.rb', line 53 def lines @lines end |
Class Method Details
.of(source) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# 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 |
Instance Method Details
#[](scope) ⇒ Object
74 75 76 77 |
# 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) ⇒ Object
79 80 81 |
# File 'lib/i18n_checker/cache.rb', line 79 def line_of(line_number) lines[line_number] end |
#lines_of(range) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Object
93 94 95 |
# File 'lib/i18n_checker/cache.rb', line 93 def to_s lines.values.join("\n") end |