Class: Glyr::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/glyr/results.rb

Defined Under Namespace

Modules: Image, Text

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer, result = nil) ⇒ Result

Returns a new instance of Result.



89
90
91
92
# File 'lib/glyr/results.rb', line 89

def initialize (pointer, result = nil)
	@internal = pointer.is_a?(FFI::Pointer) ? C::MemCache.new(pointer) : pointer
	@result   = result
end

Class Method Details

.copy(struct) ⇒ Object

:nodoc:



72
73
74
75
76
77
78
79
80
81
# File 'lib/glyr/results.rb', line 72

def self.copy (struct) # :nodoc:
	return if struct[:type] == :noidea

	pointer = C.glyr_cache_copy(struct)

	::Glyr.const_get(struct[:type].to_s.capitalize.gsub(/_(\w)/) { $1.upcase }).
		new(pointer).tap {|data|
			ObjectSpace.define_finalizer data, finalizer(pointer)
		}
end

.finalizer(pointer) ⇒ Object

:nodoc:



83
84
85
86
87
# File 'lib/glyr/results.rb', line 83

def self.finalizer (pointer) # :nodoc:
	proc {
		C.glyr_cache_free(pointer)
	}
end

.wrap(struct, result) ⇒ Object

:nodoc:



65
66
67
68
69
70
# File 'lib/glyr/results.rb', line 65

def self.wrap (struct, result) # :nodoc:
	return if struct[:type] == :noidea

	::Glyr.const_get(struct[:type].to_s.capitalize.gsub(/_(\w)/) { $1.upcase }).
		new(struct, result)
end

Instance Method Details

#cloneObject Also known as: dup



94
95
96
# File 'lib/glyr/results.rb', line 94

def clone
	self.class.copy(to_native)
end

#dataObject



100
101
102
# File 'lib/glyr/results.rb', line 100

def data
	to_native[:data].typecast(:string, to_native[:size])
end

#md5Object



124
125
126
# File 'lib/glyr/results.rb', line 124

def md5
	to_native[:md5sum]
end

#ratingObject



112
113
114
# File 'lib/glyr/results.rb', line 112

def rating
	to_native[:rating]
end

#rating=(value) ⇒ Object



116
117
118
# File 'lib/glyr/results.rb', line 116

def rating= (value)
	to_native[:rating] = value
end

#sourceObject



108
109
110
# File 'lib/glyr/results.rb', line 108

def source
	Glyr.providers[type].sources[to_native[:prov].typecast(:string)]
end

#to_nativeObject



128
129
130
# File 'lib/glyr/results.rb', line 128

def to_native
	@internal
end

#typeObject



120
121
122
# File 'lib/glyr/results.rb', line 120

def type
	to_native[:type]
end

#urlObject



104
105
106
# File 'lib/glyr/results.rb', line 104

def url
	to_native[:dsrc].typecast(:string)
end