Class: PhotoUtils::Camera
- Inherits:
-
Object
- Object
- PhotoUtils::Camera
- Defined in:
- lib/photo_utils/camera.rb
Constant Summary collapse
- CAMERAS_PATH =
Path.new(ENV['HOME']) / '.cameras.rb'
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#formats ⇒ Object
Returns the value of attribute formats.
-
#lens ⇒ Object
Returns the value of attribute lens.
-
#lenses ⇒ Object
Returns the value of attribute lenses.
-
#max_shutter ⇒ Object
Returns the value of attribute max_shutter.
-
#min_shutter ⇒ Object
Returns the value of attribute min_shutter.
-
#name ⇒ Object
Returns the value of attribute name.
-
#shutter ⇒ Object
Returns the value of attribute shutter.
Class Method Summary collapse
Instance Method Summary collapse
- #angle_of_view ⇒ Object
-
#initialize(params = {}) ⇒ Camera
constructor
A new instance of Camera.
- #print(io = STDOUT) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Camera
Returns a new instance of Camera.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/photo_utils/camera.rb', line 37 def initialize(params={}) if params[:format] params[:formats] = [params.delete(:format)] end params.each { |k, v| send("#{k}=", v) } @format ||= @formats.first normal = @format.frame.diagonal # set the lens to the one closest to normal (diagonal of frame) @lens = @lenses.sort_by { |l| (normal - l.focal_length).abs }.first @shutter = @max_shutter end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
30 31 32 |
# File 'lib/photo_utils/camera.rb', line 30 def format @format end |
#formats ⇒ Object
Returns the value of attribute formats.
29 30 31 |
# File 'lib/photo_utils/camera.rb', line 29 def formats @formats end |
#lens ⇒ Object
Returns the value of attribute lens.
35 36 37 |
# File 'lib/photo_utils/camera.rb', line 35 def lens @lens end |
#lenses ⇒ Object
Returns the value of attribute lenses.
34 35 36 |
# File 'lib/photo_utils/camera.rb', line 34 def lenses @lenses end |
#max_shutter ⇒ Object
Returns the value of attribute max_shutter.
32 33 34 |
# File 'lib/photo_utils/camera.rb', line 32 def max_shutter @max_shutter end |
#min_shutter ⇒ Object
Returns the value of attribute min_shutter.
31 32 33 |
# File 'lib/photo_utils/camera.rb', line 31 def min_shutter @min_shutter end |
#name ⇒ Object
Returns the value of attribute name.
28 29 30 |
# File 'lib/photo_utils/camera.rb', line 28 def name @name end |
#shutter ⇒ Object
Returns the value of attribute shutter.
33 34 35 |
# File 'lib/photo_utils/camera.rb', line 33 def shutter @shutter end |
Class Method Details
.[](name) ⇒ Object
24 25 26 |
# File 'lib/photo_utils/camera.rb', line 24 def self.[](name) find(name: name) end |
.cameras ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/photo_utils/camera.rb', line 7 def self.cameras unless class_variable_defined?('@@cameras') if CAMERAS_PATH.exist? @@cameras = eval(CAMERAS_PATH.read) end end @@cameras end |
.find(params) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/photo_utils/camera.rb', line 16 def self.find(params) if (sel = params[:name]) cameras.find { |c| sel === c.name } else raise "Don't know how to search for camera with params: #{params.inspect}" end end |
Instance Method Details
#angle_of_view ⇒ Object
61 62 63 64 |
# File 'lib/photo_utils/camera.rb', line 61 def angle_of_view raise "Need focal length and format size to determine angle of view" unless @lens && @lens.focal_length && @format @format.angle_of_view(@lens.focal_length) end |
#print(io = STDOUT) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/photo_utils/camera.rb', line 66 def print(io=STDOUT) io.puts "#{@name}: format: #{@format}, shutter: #{@max_shutter} - #{@min_shutter}" @lenses.sort_by(&:focal_length).each do |lens| io.puts "\t%s %s: focal length: %s (35mm equiv: %s), aperture: %s~%s" % [ lens == self.lens ? '*' : ' ', lens.name, lens.focal_length.format_metric(1), @format.focal_length_equivalent(lens.focal_length).format_metric(1), lens.max_aperture, lens.min_aperture, ] end end |