Module: Iot::Destroy
- Included in:
- Iot
- Defined in:
- lib/iot/destroy.rb
Instance Method Summary collapse
- #destroy(destroy_type, name) ⇒ Object
- #destroy_characteristic(char_name) ⇒ Object
- #destroy_service(service_name) ⇒ Object
Instance Method Details
#destroy(destroy_type, name) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/iot/destroy.rb', line 7 def destroy(destroy_type, name) if destroy_type == "service" destroy_service name elsif destroy_type == "characteristic" destroy_characteristic name end end |
#destroy_characteristic(char_name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/iot/destroy.rb', line 15 def destroy_characteristic char_name yaml = load_yaml_body if yaml.empty? puts "No Yaml file" return end deviceinfo = yaml["deviceinfo"] services = deviceinfo["services"] services.each do |service| chars = service["chars"] chars.each do |characteristic| if characteristic["name"] == char_name chars.delete characteristic puts "Destroy characteristic: #{char_name}" refresh_yaml_body yaml puts yaml return end end end puts "No such service: #{char_name}" end |
#destroy_service(service_name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/iot/destroy.rb', line 43 def destroy_service service_name yaml = load_yaml_body if yaml.empty? puts "No Yaml file" return end deviceinfo = yaml["deviceinfo"] services = deviceinfo["services"] services.each do |service| if service["name"] == service_name services.delete service puts "Destory service: #{service_name}" # YAMLファイルの内容をサービスを追加したものに変更 refresh_yaml_body yaml puts yaml return end end puts "No such service: #{service_name}" end |