Module: AMEE::Shell

Defined in:
lib/amee/shell.rb

Instance Method Summary collapse

Instance Method Details

#amee_helpObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/amee/shell.rb', line 7

def amee_help
  puts "AMEE shell - version #{AMEE::VERSION::STRING}"
  puts "--------------------------"
  puts "Commands:"
  puts " ls"
  puts "            - display contents of current category."
  puts " cd 'path'"
  puts "            - change category. Path must be a quoted string. You can use things like '/data', '..', or 'subcategory'."
  puts " pwd"
  puts "            - display current category path."
  puts " cat 'name'"
  puts "            - display contents of data item called 'name' within the current category."
  puts " set_value 'item_name', 'value_name', value"
  puts "            - set the value 'value_name' inside 'item_name' to value."
  puts " amee_help"
  puts "            - display this help text."
end

#cat(name) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/amee/shell.rb', line 52

def cat(name)
  item = @@category.items.detect { |i| i[:path].match("^#{name}") }
  fullpath = "#{@@category.full_path}/#{item[:path]}"
  item = AMEE::Data::Item.get($connection, fullpath)
  puts fullpath
  puts "Label: #{item.label}"
  puts "Values:"
  item.values.each do |v|
    puts " - #{v[:name]}: #{v[:value]}"
  end
  nil
end

#cd(path) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/amee/shell.rb', line 41

def cd(path)
  if path == '..'
    path_components = @@category.full_path.split('/')
    path = path_components.first(path_components.size - 1).join('/')
  elsif !path.match(/^\/.*/)
    path = @@category.full_path + '/' + path
  end
  @@category = AMEE::Data::Category.get($connection, path)
  @@category.full_path
end

#lsObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/amee/shell.rb', line 25

def ls
  puts "Categories:"
  @@category.children.each do |c|
    puts " - #{c[:path]}"
  end
  puts "Items:"
  @@category.items.each do |i|
    puts " - #{i[:path]} (#{i[:label]})"
  end
  nil
end

#pwdObject



37
38
39
# File 'lib/amee/shell.rb', line 37

def pwd
  @@category.full_path
end

#set_value(item, name, value) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/amee/shell.rb', line 65

def set_value(item, name, value)
  item = @@category.items.detect { |i| i[:path].match("^#{item}") }
  fullpath = "#{@@category.full_path}/#{item[:path]}/#{name}"
  itemval = AMEE::Data::ItemValue.get($connection, fullpath)
  itemval.value = value
  itemval.save!
end