Class: Mayl::Commands::Get

Inherits:
Object
  • Object
show all
Defined in:
lib/mayl/commands/get.rb

Overview

Public: The Get command accepts a key and returns a summary of the values for that key in every locale.

Example

command = Get.new(env, 'activerecord.models.post')
command.execute
# Outputs:
#   ca: Article
#   es: Artículo
#   en: Post

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, key) ⇒ Get

Public: Initializes a new Get command.

env - the global environment key - the String key to get the value of



22
23
24
25
# File 'lib/mayl/commands/get.rb', line 22

def initialize(env, key)
  @env = env
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



16
17
18
# File 'lib/mayl/commands/get.rb', line 16

def key
  @key
end

Instance Method Details

#executeObject

Public: Executes the command, iterating over each locale, asking the value for the key, and printing it out.

Returns the key.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mayl/commands/get.rb', line 31

def execute
  locales.each do |locale|
    result = locale.get qualified_key
    name   = locale.to_s
    if result.is_a? String
      print "  #{name}: #{result}\n"
    else
      print "  #{name}: (empty)\n"
    end
  end
  @key
end