Class: PhotoUtils::Time

Inherits:
Value show all
Defined in:
lib/photo_utils/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#<=>, #==, #decr, #incr, #initialize

Methods inherited from Float

#format, #prec

Constructor Details

This class inherits a constructor from PhotoUtils::Value

Class Method Details

.new_from_seconds(s) ⇒ Object



5
6
7
# File 'lib/photo_utils/time.rb', line 5

def self.new_from_seconds(s)
  new(s)
end

.new_from_v(v) ⇒ Object



9
10
11
# File 'lib/photo_utils/time.rb', line 9

def self.new_from_v(v)
  new(2 ** -v.to_f)
end

Instance Method Details

#format_secondsObject



21
22
23
24
25
26
27
# File 'lib/photo_utils/time.rb', line 21

def format_seconds
  if (seconds = to_seconds) < 1
    '1/' + (1/self).format(1)
  else
    seconds.format
  end + 's'
end

#format_valueObject



29
30
31
# File 'lib/photo_utils/time.rb', line 29

def format_value
  "Tv:#{to_v.format(10)}"
end

#reciprocityObject



46
47
48
49
# File 'lib/photo_utils/time.rb', line 46

def reciprocity
  tc = self + (0.3 * (self ** 1.62))
  Time.new(tc)
end

#to_s(format = :seconds) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/photo_utils/time.rb', line 33

def to_s(format=:seconds)
  case format
  when :seconds
    format_seconds
  when :value
    format_value
  else
    raise "Unknown format: #{format.inspect}"
  end
end

#to_secondsObject



17
18
19
# File 'lib/photo_utils/time.rb', line 17

def to_seconds
  to_f
end

#to_vObject



13
14
15
# File 'lib/photo_utils/time.rb', line 13

def to_v
  -Math.log2(self.to_f)
end