Class: S7::DateTimeAttribute

Inherits:
Attribute show all
Defined in:
lib/s7/attribute.rb

Overview

日時の属性を表現する。

Instance Attribute Summary

Attributes inherited from Attribute

#editabled, #name, #protected, #secret

Instance Method Summary collapse

Methods inherited from Attribute

create_instance, #editable?, #initialize, #protected?, #secret?, #type, types, #value, #value=

Methods included from GetText

#N_, #_, bindtextdomain, included

Constructor Details

This class inherits a constructor from S7::Attribute

Instance Method Details

#display_value(secret = @secret) ⇒ Object

value を表示するために文字列に変換する。 secret が true であれば「*」を返す。 そうでなければ、「%Y/%m/%d %H:%M:%S」でフォーマットした文字列を返す。 また、時分秒が全て0の場合は「%Y/%m/%d」でフォーマットする。



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/s7/attribute.rb', line 184

def display_value(secret = @secret)
  if secret
    return "*"
  else
    format = "%Y/%m/%d"
    if value.hour != 0 || value.min != 0 || value.sec != 0
      format << " %H:%M:%S"
    end
    return value.strftime(format)
  end
end