class Translatomatic::Metadata
Parses tm.context comments in resource files
Attributes
context[R]
Public Class Methods
new()
click to toggle source
# File lib/translatomatic/metadata.rb, line 6 def initialize reset end
Public Instance Methods
add_context(context)
click to toggle source
Add to the current context @param context [String] A context string
# File lib/translatomatic/metadata.rb, line 39 def add_context(context) return unless context.present? @current_context ||= [] @current_context << context.strip end
assign_key(key, options = {})
click to toggle source
Assign current metadata to the given key @param key [String] name of the key
# File lib/translatomatic/metadata.rb, line 25 def assign_key(key, options = {}) if @current_context.present? @context[key] = @current_context @current_context = nil unless options[:keep_context] end end
clear_context()
click to toggle source
Clear the current context
# File lib/translatomatic/metadata.rb, line 33 def clear_context @current_context = nil end
get_context(key)
click to toggle source
Find associated context(s) for a property. Contexts are defined using tm.context comments in resource files. @return [Array<String>] Context for the given key
# File lib/translatomatic/metadata.rb, line 13 def get_context(key) @context[key] end
parse_comment(comment)
click to toggle source
Parse comment text and extract metadata @return [Array] parsed context data
# File lib/translatomatic/metadata.rb, line 47 def parse_comment(comment) return nil if comment.blank? contexts = comment.scan(/tm\.context:\s*(.*)/) result = [] contexts.each do |i| add_context(i[0]) result << i[0] end result end
reset()
click to toggle source
Clear all metadata
# File lib/translatomatic/metadata.rb, line 18 def reset @context = {} @current_context = nil end