module Enolib::Selections
Constants
- DOCUMENT_BEGIN
- RANGE_BEGIN
- RANGE_END
Public Class Methods
cursor(instruction, range, position)
click to toggle source
# File lib/enolib/errors/selections.rb, line 30 def self.cursor(instruction, range, position) index = instruction[:ranges][range][position] { column: index - instruction[:ranges][:line][RANGE_BEGIN], index: index, line: instruction[:line] } end
last_in(element)
click to toggle source
# File lib/enolib/errors/selections.rb, line 12 def self.last_in(element) if (element[:type] == :field || element[:type] == :list_item || element[:type] == :fieldset_entry) && element.has_key?(:continuations) element[:continuations].last elsif element[:type] == :list && element.has_key?(:items) last_in(element[:items].last) elsif element[:type] == :fieldset && element.has_key?(:entries) last_in(element[:entries].last) elsif element[:type] == :multiline_field_begin element[:end] elsif element[:type] == :section && !element[:elements].empty? last_in(element[:elements].last) else element end end
select_comments(element)
click to toggle source
# File lib/enolib/errors/selections.rb, line 51 def self.select_comments(element) comments = element[:comments] if comments.length == 1 if comments.first.has_key?(:comment) selection(comments.first, :comment, RANGE_BEGIN, RANGE_END) else selection(comments.first, :line, RANGE_BEGIN, RANGE_END) end elsif comments.length > 1 selection(comments.first, :line, RANGE_BEGIN, comments.last, :line, RANGE_END) else selection(element, :line, RANGE_BEGIN) end end
select_element(element)
click to toggle source
# File lib/enolib/errors/selections.rb, line 67 def self.select_element(element) selection(element, :line, RANGE_BEGIN, last_in(element), :line, RANGE_END) end
select_key(element)
click to toggle source
# File lib/enolib/errors/selections.rb, line 71 def self.select_key(element) selection(element, :key, RANGE_BEGIN, RANGE_END) end
select_line(element)
click to toggle source
# File lib/enolib/errors/selections.rb, line 75 def self.select_line(element) selection(element, :line, RANGE_BEGIN, RANGE_END) end
select_template(element)
click to toggle source
# File lib/enolib/errors/selections.rb, line 79 def self.select_template(element) selection(element, :template, RANGE_BEGIN, RANGE_END) end
selection(instruction, range, position, *to)
click to toggle source
# File lib/enolib/errors/selections.rb, line 40 def self.selection(instruction, range, position, *to) to_instruction = to.find { |argument| argument.is_a?(Hash) } || instruction to_range = to.find { |argument| argument.is_a?(Symbol) } || range to_position = to.find { |argument| argument.is_a?(Numeric) } || position { from: cursor(instruction, range, position), to: cursor(to_instruction, to_range, to_position) } end