Class: ExtractI18n::Slimkeyfy::Word
- Inherits:
-
Object
- Object
- ExtractI18n::Slimkeyfy::Word
- Defined in:
- lib/extract_i18n/slimkeyfy/word.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#indentation ⇒ Object
readonly
Returns the value of attribute indentation.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
- #as_list ⇒ Object
- #extract_arguments(translation) ⇒ Object
- #extract_updated_key(translation_key_with_base) ⇒ Object
- #head ⇒ Object
-
#initialize(line) ⇒ Word
constructor
A new instance of Word.
- #tail ⇒ Object
- #unindented_line ⇒ Object
Constructor Details
#initialize(line) ⇒ Word
Returns a new instance of Word.
15 16 17 18 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 15 def initialize(line) @line = line @indentation = " " * (@line.size - unindented_line.size) end |
Instance Attribute Details
#indentation ⇒ Object (readonly)
Returns the value of attribute indentation.
5 6 7 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 5 def indentation @indentation end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
5 6 7 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 5 def line @line end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
5 6 7 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 5 def tokens @tokens end |
Class Method Details
Instance Method Details
#as_list ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 20 def as_list # check for div.foo-bar(foo=bar) has_html_form = !!@line[/^ *[\.#]?[a-z\.#-]+\(/] delimiter_items = @line. sub(/^(\s*\|)(\w)/, "\\1 \\2"). # add a whitespace to support "|string" split(has_html_form ? /(?<=[\(])| +/ : ' '). # split by whitespace or ( but keep ( drop_while { |i| i == "" } # .. but that leaves leading "" items = [] # div: div delimiter_items.reverse_each do |item| if item[/^([a-z]|\.[a-z]|#[a-z]).*:/] and items.length > 0 items[-1] = "#{item} #{items[-1]}" else items << item end end items.reverse end |
#extract_arguments(translation) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 52 def extract_arguments(translation) args = {} translation.scan(/\#{[^}]*}/).each_with_index do |arg, index| stripped_arg = arg[2..-2] key = arg[/\w+/] key += index.to_s if index > 0 translation = translation.gsub(arg, "%{#{key}}") args[key] = stripped_arg end [args, translation] end |
#extract_updated_key(translation_key_with_base) ⇒ Object
64 65 66 67 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 64 def extract_updated_key(translation_key_with_base) return "" if translation_key_with_base.blank? translation_key_with_base.split(".").last end |
#head ⇒ Object
44 45 46 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 44 def head as_list.first end |
#tail ⇒ Object
48 49 50 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 48 def tail as_list.drop(1) end |
#unindented_line ⇒ Object
40 41 42 |
# File 'lib/extract_i18n/slimkeyfy/word.rb', line 40 def unindented_line @line.sub(/^\s*/, "") end |