Class: BLM::Row

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, arguments = {}, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rightmove.rb', line 50

def method_missing(method, arguments = {}, &block)
	unless @attributes[method].nil?
		value = @attributes[method] 
		if arguments[:instantiate_with]
			return value unless value =~ /\.jpg/i
			if arguments[:instantiate_with].instance_of?(Zip::ZipFile)
				zip = arguments[:instantiate_with]
			else
				zip = Zip::ZipFile.open(arguments[:instantiate_with])
			end
			matching_files = zip.entries.select {|v| v.to_s =~ /#{value}/ }
			unless matching_files.empty?
				file = StringIO.new( zip.read(matching_files.first) )
				file.class.class_eval { attr_accessor :original_filename, :content_type }
				file.original_filename = matching_files.first.to_s
				file.content_type = "image/jpg"
				return file
			end
		else
			value
		end
	end
end

Instance Method Details

#media_fieldsObject



74
75
76
# File 'lib/rightmove.rb', line 74

def media_fields
	self.attributes.select {|k,v| k.to_s =~ /media_(image|floor_plan)_.*/i }
end