Sha256: 9427737f00ae3f0790b32f4b98e4842385785f498d8cb413eef3460672dd589a

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

module I18nFlow::YamlAstProxy
  module NodeMetaData
    def num_lines
      return 1 unless end_line
      end_line - start_line + 1
    end

    def key
      scopes.last
    end

    def locale
      scopes.first
    end

    def full_key
      scopes.join('.')
    end

    def start_line
      node.start_line + line_correction
    end

    def end_line
      node.end_line + line_correction
    end

    def start_column
      node.start_column
    end

    def end_column
      node.end_column
    end

    def anchor
      node.anchor
    end

    def sequence?
      is_a?(Sequence)
    end

    def mapping?
      is_a?(Mapping)
    end

    def scalar?
      node.is_a?(Psych::Nodes::Scalar)
    end

    def alias?
      node.is_a?(Psych::Nodes::Alias)
    end

    def has_anchor?
      !!anchor
    end

    def marked_as_todo?
      @tag == :todo
    end

    def marked_as_only?
      @tag == :only
    end

    def todo_locales
      @todo_locales ||= []
    end

    def valid_locales
      @valid_locales ||= []
    end

    def valid_locale?
      valid_locales.empty? || valid_locales.include?(locale)
    end

  private

    def line_correction
      node.is_a?(Psych::Nodes::Scalar) ? 1 : 0
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
i18n_flow-0.2.3 lib/i18n_flow/yaml_ast_proxy/node_meta_data.rb
i18n_flow-0.2.2 lib/i18n_flow/yaml_ast_proxy/node_meta_data.rb
i18n_flow-0.2.1 lib/i18n_flow/yaml_ast_proxy/node_meta_data.rb
i18n_flow-0.2.0 lib/i18n_flow/yaml_ast_proxy/node_meta_data.rb
i18n_flow-0.1.0 lib/i18n_flow/yaml_ast_proxy/node_meta_data.rb