Class: S7::Attribute

Inherits:
Object
  • Object
show all
Includes:
GetText
Defined in:
lib/s7/attribute.rb

Overview

属性を表現する。

Constant Summary collapse

@@attribute_classes =

サポートしている属性のクラス。

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GetText

#N_, #_, bindtextdomain, included

Constructor Details

#initialize(options) ⇒ Attribute

Returns a new instance of Attribute.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/s7/attribute.rb', line 46

def initialize(options)
  self.name = options["name"]
  self.value = options["value"]
  self.secret = options["secret"] ? true : false
  if options.key?("editabled")
    self.editabled = options["editabled"] ? true : false
  else
    self.editabled = true
  end
  self.protected = options["protected"] ? true : false
end

Instance Attribute Details

#editabledObject

値を編集できるかどうか。true であれば編集でき、false であれ ばそうでない。



40
41
42
# File 'lib/s7/attribute.rb', line 40

def editabled
  @editabled
end

#nameObject

名前。



33
34
35
# File 'lib/s7/attribute.rb', line 33

def name
  @name
end

#protectedObject

削除できるかどうか。true であれば削除できず、false であれ ばそうでない。



44
45
46
# File 'lib/s7/attribute.rb', line 44

def protected
  @protected
end

#secretObject

機密情報かどうか。true であれば機密情報、false であればそうでない。



36
37
38
# File 'lib/s7/attribute.rb', line 36

def secret
  @secret
end

Class Method Details

.create_instance(type, options) ⇒ Object



15
16
17
# File 'lib/s7/attribute.rb', line 15

def create_instance(type, options)
  return @@attribute_classes[type].new(options)
end

.typesObject

属性の型名の配列を返す。



20
21
22
# File 'lib/s7/attribute.rb', line 20

def types
  return @@attribute_classes.keys
end

Instance Method Details

#display_value(secret = @secret) ⇒ Object

value を表示するために文字列に変換する。 このとき、 secret が true であれば「*」でマスクする。



101
102
103
104
105
106
107
# File 'lib/s7/attribute.rb', line 101

def display_value(secret = @secret)
  if secret
    return "*" * value.to_s.length
  else
    return value.to_s
  end
end

#editable?Boolean

ユーザによる値の編集ができるかどうかを取得する。 編集できる場合、true を返す。そうでなければ true を返す。

Returns:

  • (Boolean)


89
90
91
# File 'lib/s7/attribute.rb', line 89

def editable?
  return editabled ? true : false
end

#protected?Boolean

ユーザによる削除ができるかどうかを取得する。 削除できる場合、true を返す。そうでなければ true を返す。

Returns:

  • (Boolean)


95
96
97
# File 'lib/s7/attribute.rb', line 95

def protected?
  return protected ? true : false
end

#secret?Boolean

機密情報かどうかを取得する。 機密情報の場合、true を返す。そうでなれば false を返す。

Returns:

  • (Boolean)


83
84
85
# File 'lib/s7/attribute.rb', line 83

def secret?
  return secret ? true : false
end

#typeObject

属性の型を取得する。



77
78
79
# File 'lib/s7/attribute.rb', line 77

def type
  return self.class.const_get("TYPE")
end

#valueObject

value を取得する。



59
60
61
62
63
64
65
# File 'lib/s7/attribute.rb', line 59

def value
  if @value.nil?
    return nil
  else
    return get_value
  end
end

#value=(val) ⇒ Object

value を設定する。



68
69
70
71
72
73
74
# File 'lib/s7/attribute.rb', line 68

def value=(val)
  if val.nil?
    @value = val
  else
    set_value(val)
  end
end