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:si-assess="http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/ASSESSMENT/"
xmlns:si-basic="http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/BASIC/"
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.
33
34
35
36
37
|
# File 'lib/cul_image_props/image/properties/types.rb', line 33
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.
25
26
27
|
# File 'lib/cul_image_props/image/properties/types.rb', line 25
def nodeset
@nodeset
end
|
Instance Method Details
#[](key) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/cul_image_props/image/properties/types.rb', line 51
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
64
65
66
67
68
69
|
# File 'lib/cul_image_props/image/properties/types.rb', line 64
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
94
95
96
|
# File 'lib/cul_image_props/image/properties/types.rb', line 94
def extent=(value)
add_dt_prop("dcmi", "extent", 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
|
#length=(value) ⇒ Object
90
91
92
|
# File 'lib/cul_image_props/image/properties/types.rb', line 90
def length=(value)
add_dt_prop("si-basic", "imageLength", value)
end
|
#ord_value(val) ⇒ Object
this is a hack to deal with Ruby 1.9 shenanigans
39
40
41
42
43
44
45
46
47
|
# File 'lib/cul_image_props/image/properties/types.rb', line 39
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=(name) ⇒ Object
71
72
73
74
75
76
|
# File 'lib/cul_image_props/image/properties/types.rb', line 71
def sampling_unit=(name)
prop = @ng_xml.create_element("samplingFrequencyUnit")
@ng_xml.root.namespace_definitions.each { |ns| prop.namespace = ns if ns.prefix == "si-assess" }
@ng_xml.root.add_child( prop )
prop.set_attribute("rdf:resource", prop.namespace.href + name)
end
|
#width=(value) ⇒ Object
86
87
88
|
# File 'lib/cul_image_props/image/properties/types.rb', line 86
def width=(value)
add_dt_prop("si-basic", "imageWidth", value)
end
|
#x_sampling_freq=(value) ⇒ Object
78
79
80
|
# File 'lib/cul_image_props/image/properties/types.rb', line 78
def x_sampling_freq=(value)
add_dt_prop("si-assess", "xSamplingFrequency", value)
end
|
#y_sampling_freq=(value) ⇒ Object
82
83
84
|
# File 'lib/cul_image_props/image/properties/types.rb', line 82
def y_sampling_freq=(value)
add_dt_prop("si-assess", "ySamplingFrequency", value)
end
|