Class: Cul::Image::Properties::Base
- Inherits:
-
Object
- Object
- Cul::Image::Properties::Base
show all
- Defined in:
- lib/cul_image_props/image/properties/types.rb
Constant Summary
collapse
- BASE_XML =
Nokogiri::XML.parse(<<-xml
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:exif="http://www.w3.org/2003/12/exif/ns#"
xmlns:dcmi="http://purl.org/dc/terms/"></rdf:Description>
xml
)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(srcfile = nil) ⇒ Base
Returns a new instance of Base.
31
32
33
34
35
|
# File 'lib/cul_image_props/image/properties/types.rb', line 31
def initialize(srcfile=nil)
@src = srcfile
@src.rewind
@ng_xml = BASE_XML.clone
end
|
Instance Attribute Details
#nodeset ⇒ Object
Returns the value of attribute nodeset.
24
25
26
|
# File 'lib/cul_image_props/image/properties/types.rb', line 24
def nodeset
@nodeset
end
|
Instance Method Details
#[](key) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/cul_image_props/image/properties/types.rb', line 49
def [](key)
result = nil
nodeset.each { |node|
if (node.namespace.href + node.name) == key
if node.attribute('resource').nil?
result = node.text
else
result = node.attribute('resource').value
end
end
}
result
end
|
#add_dt_prop(prefix, name, value) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/cul_image_props/image/properties/types.rb', line 62
def add_dt_prop(prefix, name, value)
prop = @ng_xml.create_element(name)
@ng_xml.root.namespace_definitions.each { |ns| prop.namespace = ns if ns.prefix == prefix }
prop.add_child(@ng_xml.create_text_node(value.to_s))
@ng_xml.root.add_child( prop )
end
|
#extent=(value) ⇒ Object
90
91
92
|
# File 'lib/cul_image_props/image/properties/types.rb', line 90
def extent=(value)
add_dt_prop("dcmi", "extent", value)
end
|
94
95
96
|
# File 'lib/cul_image_props/image/properties/types.rb', line 94
def format=(value)
add_dt_prop("dcmi", "format", value)
end
|
#hex_inspect(str) ⇒ Object
98
99
100
101
102
|
# File 'lib/cul_image_props/image/properties/types.rb', line 98
def hex_inspect(str)
result = []
(0...str.length).each {|ix| result << str[ix].to_s(16)}
result.inspect
end
|
#inspect ⇒ Object
104
105
106
|
# File 'lib/cul_image_props/image/properties/types.rb', line 104
def inspect
@ng_xml.to_s
end
|
#length=(value) ⇒ Object
86
87
88
|
# File 'lib/cul_image_props/image/properties/types.rb', line 86
def length=(value)
add_dt_prop("exif", "imageLength", value)
end
|
#ord_value(val) ⇒ Object
this is a hack to deal with Ruby 1.9 shenanigans
37
38
39
40
41
42
43
44
45
|
# File 'lib/cul_image_props/image/properties/types.rb', line 37
def ord_value(val)
if val.is_a? Fixnum
return val
elsif val.is_a? String
return val.unpack('C')[0]
else
return val.to_i
end
end
|
#sampling_unit=(value) ⇒ Object
69
70
71
72
|
# File 'lib/cul_image_props/image/properties/types.rb', line 69
def sampling_unit=(value)
raise "resolutionUnit values must be in the set #{RESOLUTION_VALUES.inspect}" unless RESOLUTION_VALUES.include? value
add_dt_prop("exif", "resolutionUnit", value)
end
|
#width=(value) ⇒ Object
82
83
84
|
# File 'lib/cul_image_props/image/properties/types.rb', line 82
def width=(value)
add_dt_prop("exif", "imageWidth", value)
end
|
#x_sampling_freq=(value) ⇒ Object
74
75
76
|
# File 'lib/cul_image_props/image/properties/types.rb', line 74
def x_sampling_freq=(value)
add_dt_prop("exif", "xResolution", value)
end
|
#y_sampling_freq=(value) ⇒ Object
78
79
80
|
# File 'lib/cul_image_props/image/properties/types.rb', line 78
def y_sampling_freq=(value)
add_dt_prop("exif", "yResolution", value)
end
|