idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
5,700
def run ( interval = 600 ) @log . debug ( 'aggregator start' ) loop do @feeds . each do | feed | @log . debug ( 'aggregate ' + feed . url ) options = { allow_redirections : :safe } unless feed . validate_cert @log . debug ( 'aggregate certificate validation: false' ) options [ :ssl_verify_mode ] = OpenSSL :: SSL :: VER...
Get file enclosures from all feeds items and call on_new_item callback with torrent file URL as argument .
5,701
def callback ( * names ) names . each do | name | self . class_eval do define_method name , -> ( * args , & block ) do @callbacks ||= { } if block @callbacks [ name ] = block elsif @callbacks [ name ] @callbacks [ name ] . call ( * args ) end end end end end
Define callback method .
5,702
def start resolve_parameters version_info = version_info @service , @version env_variables = version_info [ "envVariables" ] || { } beta_settings = version_info [ "betaSettings" ] || { } cloud_sql_instances = beta_settings [ "cloud_sql_instances" ] || [ ] image = version_info [ "deployment" ] [ "container" ] [ "image" ...
Executes the command synchronously . Streams the logs back to standard out and does not return until the command has completed or timed out .
5,703
def device_names @device_names ||= begin names = [ ] cmd_output = '' count = 0 while cmd_output . empty? || ! cmd_output . split ( 'DirectShow' ) [ 2 ] cmd_output = system_call ( ffpmeg_list_devices_cmd , true ) count += 1 raise 'failed to find a video capture device with ffmpeg -list_devices' if count == 5 sleep 0.1 e...
inspired by this code from
5,704
def run_capture puts '*** Preserving this moment in history.' unless capture_stealth self . snapshot_loc = config . raw_image ( image_file_type ) self . main_image = config . main_image ( sha , image_file_type ) capturer = Platform . capturer_class ( capture_animated? ) . new ( capture_device : capture_device , capture...
the main capture
5,705
def get_range ( col_index ) col_num = col_index + 1 old_range = self . locate_range ( col_index ) if old_range . nil? then new_range = RubyXL :: ColumnRange . new else if old_range . min == col_num && old_range . max == col_num then return old_range elsif old_range . min == col_num then new_range = old_range . dup old_...
Locate an existing column range make a new one if not found or split existing column range into multiples .
5,706
def save ( dst_file_path = nil ) dst_file_path ||= root . source_file_path extension = File . extname ( dst_file_path ) unless %w{ .xlsx .xlsm } . include? ( extension . downcase ) raise "Unsupported extension: #{extension} (only .xlsx and .xlsm files are supported)." end File . open ( dst_file_path , "wb" ) { | output...
Save the resulting XLSX file to the specified location
5,707
def [] ( ind ) case ind when Integer then worksheets [ ind ] when String then worksheets . find { | ws | ws . sheet_name == ind } end end
Finds worksheet by its name or numerical index
5,708
def add_worksheet ( name = nil ) if name . nil? then n = 0 begin name = SHEET_NAME_TEMPLATE % ( n += 1 ) end until self [ name ] . nil? end new_worksheet = Worksheet . new ( :workbook => self , :sheet_name => name ) worksheets << new_worksheet new_worksheet end
Create new simple worksheet and add it to the workbook worksheets
5,709
def validate_workbook ( ) unless @workbook . nil? || @workbook . worksheets . nil? return if @workbook . worksheets . any? { | sheet | sheet . equal? ( self ) } end raise "This worksheet #{self} is not in workbook #{@workbook}" end
validates Workbook ensures that this worksheet is in
5,710
def ensure_cell_exists ( row_index , column_index = 0 ) validate_nonnegative ( row_index ) validate_nonnegative ( column_index ) sheet_data . rows [ row_index ] || add_row ( row_index ) end
Ensures that storage space for a cell with + row_index + and + column_index + exists in + sheet_data + arrays growing them up if necessary .
5,711
def change_fill ( rgb = 'ffffff' ) validate_worksheet Color . validate_color ( rgb ) self . style_index = workbook . modify_fill ( self . style_index , rgb ) end
Changes fill color of cell
5,712
def change_font_name ( new_font_name = 'Verdana' ) validate_worksheet font = get_cell_font . dup font . set_name ( new_font_name ) update_font_references ( font ) end
Changes font name of cell
5,713
def change_font_size ( font_size = 10 ) validate_worksheet raise 'Argument must be a number' unless font_size . is_a? ( Integer ) || font_size . is_a? ( Float ) font = get_cell_font . dup font . set_size ( font_size ) update_font_references ( font ) end
Changes font size of cell
5,714
def change_font_color ( font_color = '000000' ) validate_worksheet Color . validate_color ( font_color ) font = get_cell_font . dup font . set_rgb_color ( font_color ) update_font_references ( font ) end
Changes font color of cell
5,715
def change_font_italics ( italicized = false ) validate_worksheet font = get_cell_font . dup font . set_italic ( italicized ) update_font_references ( font ) end
Changes font italics settings of cell
5,716
def change_font_bold ( bolded = false ) validate_worksheet font = get_cell_font . dup font . set_bold ( bolded ) update_font_references ( font ) end
Changes font bold settings of cell
5,717
def change_font_underline ( underlined = false ) validate_worksheet font = get_cell_font . dup font . set_underline ( underlined ) update_font_references ( font ) end
Changes font underline settings of cell
5,718
def update_font_references ( modified_font ) xf = workbook . register_new_font ( modified_font , get_cell_xf ) self . style_index = workbook . register_new_xf ( xf ) end
Helper method to update the font array and xf array
5,719
def font_switch ( change_type , arg ) case change_type when Worksheet :: NAME then change_font_name ( arg ) when Worksheet :: SIZE then change_font_size ( arg ) when Worksheet :: COLOR then change_font_color ( arg ) when Worksheet :: ITALICS then change_font_italics ( arg ) when Worksheet :: BOLD then change_font_bold ...
Performs correct modification based on what type of change_type is specified
5,720
def get_column_width_raw ( column_index = 0 ) validate_workbook validate_nonnegative ( column_index ) range = cols . locate_range ( column_index ) range && range . width end
Get raw column width value as stored in the file
5,721
def change_column_width_raw ( column_index , width ) validate_workbook ensure_cell_exists ( 0 , column_index ) range = cols . get_range ( column_index ) range . width = width range . custom_width = true end
Set raw column width value
5,722
def change_row_font ( row_index , change_type , arg , font ) validate_workbook ensure_cell_exists ( row_index ) xf = workbook . register_new_font ( font , get_row_xf ( row_index ) ) row = sheet_data [ row_index ] row . style_index = workbook . register_new_xf ( xf ) row . cells . each { | c | c . font_switch ( change_t...
Helper method to update the row styles array change_type - NAME or SIZE or COLOR etc main method to change font called from each separate font mutator method
5,723
def change_column_font ( column_index , change_type , arg , font , xf ) validate_workbook ensure_cell_exists ( 0 , column_index ) xf = workbook . register_new_font ( font , xf ) cols . get_range ( column_index ) . style_index = workbook . register_new_xf ( xf ) sheet_data . rows . each { | row | c = row && row [ column...
Helper method to update the fonts and cell styles array main method to change font called from each separate font mutator method
5,724
def merge_cells ( start_row , start_col , end_row , end_col ) validate_workbook self . merged_cells ||= RubyXL :: MergedCells . new merged_cells << RubyXL :: MergedCell . new ( :ref => RubyXL :: Reference . new ( start_row , end_row , start_col , end_col ) ) end
Merges cells within a rectangular area
5,725
def environment_variables vars = @process . environment_variables . merge ( { 'PROC_NAME' => self . description , 'PID_FILE' => self . pid_file_path , 'APP_ROOT' => @process . config . root } ) vars [ 'PORT' ] = @port . to_s if @port vars end
Return an array of environment variables that should be set
5,726
def pid_from_file if File . exist? ( pid_file_path ) pid = File . read ( pid_file_path ) pid . length > 0 ? pid . strip . to_i : nil else nil end end
Return the PID that is in the instances process PID file
5,727
def start if stopping? Procodile . log ( @process . log_color , description , "Process is stopped/stopping therefore cannot be started again." ) return false end update_pid if running? Procodile . log ( @process . log_color , description , "Already running with PID #{@pid}" ) nil else if @supervisor . run_options [ :po...
Start a new instance of this process
5,728
def stop @stopping = Time . now update_pid if self . running? Procodile . log ( @process . log_color , description , "Sending #{@process.term_signal} to #{@pid}" ) :: Process . kill ( @process . term_signal , pid ) else Procodile . log ( @process . log_color , description , "Process already stopped" ) end end
Send this signal the signal to stop and mark the instance in a state that tells us that we want it to be stopped .
5,729
def restart Procodile . log ( @process . log_color , description , "Restarting using #{@process.restart_mode} mode" ) update_pid case @process . restart_mode when 'usr1' , 'usr2' if running? :: Process . kill ( @process . restart_mode . upcase , @pid ) @tag = @supervisor . tag if @supervisor . tag Procodile . log ( @pr...
Retarts the process using the appropriate method from the process configuraiton
5,730
def update_pid pid_from_file = self . pid_from_file if pid_from_file && pid_from_file != @pid @pid = pid_from_file @started_at = File . mtime ( self . pid_file_path ) Procodile . log ( @process . log_color , description , "PID file changed. Updated pid to #{@pid}" ) true else false end end
Update the locally cached PID from that stored on the file system .
5,731
def check ( options = { } ) return if failed? if self . running? true else return check if update_pid if @supervisor . allow_respawning? if can_respawn? Procodile . log ( @process . log_color , description , "Process has stopped. Respawning..." ) start add_respawn elsif respawns >= @process . max_respawns Procodile . l...
Check the status of this process and handle as appropriate .
5,732
def allocate_port ( max_attempts = 10 ) attempts = 0 until @port attempts += 1 possible_port = rand ( 10000 ) + 20000 if self . port_available? ( possible_port ) Procodile . log ( @process . log_color , description , "Allocated port as #{possible_port}" ) return @port = possible_port elsif attempts >= max_attempts rais...
Find a port number for this instance to listen on . We just check that nothing is already listening on it . The process is expected to take it straight away if it wants it .
5,733
def port_available? ( port ) case @process . network_protocol when 'tcp' server = TCPServer . new ( '127.0.0.1' , port ) server . close true when 'udp' server = UDPSocket . new server . bind ( '127.0.0.1' , port ) server . close true else raise Procodile :: Error , "Invalid network_protocol '#{@process.network_protocol...
Is the given port available?
5,734
def without_rbenv ( & block ) previous_environment = ENV . select { | k , v | k =~ / \A \_ / } if previous_environment . size > 0 previous_environment . each { | key , value | ENV [ key ] = nil } previous_environment [ 'PATH' ] = ENV [ 'PATH' ] ENV [ 'PATH' ] = ENV [ 'PATH' ] . split ( ':' ) . select { | p | ! ( p =~ /...
If procodile is executed through rbenv it will pollute our environment which means that any spawned processes will be invoked with procodile s ruby rather than the ruby that the application wishes to use
5,735
def environment_variables global_variables = @config . environment_variables process_vars = @config . process_options [ @name ] ? @config . process_options [ @name ] [ 'env' ] || { } : { } process_local_vars = @config . local_process_options [ @name ] ? @config . local_process_options [ @name ] [ 'env' ] || { } : { } g...
Return all environment variables for this process
5,736
def to_hash { :name => self . name , :log_color => self . log_color , :quantity => self . quantity , :max_respawns => self . max_respawns , :respawn_window => self . respawn_window , :command => self . command , :restart_mode => self . restart_mode , :log_path => self . log_path , :removed => self . removed ? true : fa...
Return a hash
5,737
def app_options if ambiguous? hash = { } @global_options . each_with_index do | option , i | hash [ i ] = option [ 'name' ] || option [ 'root' ] end hash else { } end end
Return an hash of possible options to settle the ambiguity
5,738
def map_with ( * names ) [ self , * names . map { | name | mappers [ name ] } ] . reduce { | a , e | composite_class . new ( a , e ) } end
Send data through specified mappers
5,739
def plugins_for ( type , adapter ) case type when :configuration then configuration when :command then commands . adapter ( adapter ) when :mapper then mappers . adapter ( adapter ) when :relation then relations . adapter ( adapter ) when :schema then schemas . adapter ( adapter ) end end
Determine which specific registry to use
5,740
def register ( name , mod , options ) elements [ name ] = plugin_type . new ( mod , options ) end
Assign a plugin to this environment registry
5,741
def plugin_name ( plugin ) tuple = elements . find { | ( _ , p ) | p . equal? ( plugin ) } tuple [ 0 ] if tuple end
Returns plugin name by instance
5,742
def fetch ( name , adapter_name = :default ) adapter ( adapter_name ) [ name ] || adapter ( :default ) [ name ] || raise ( UnknownPluginError , name ) end
Return the plugin for a given adapter
5,743
def load_entities ( entity ) Dir [ globs [ entity ] ] . map do | file | require file klass_name = case namespace when String AutoRegistrationStrategies :: CustomNamespace . new ( namespace : namespace , file : file , directory : directory ) . call when TrueClass AutoRegistrationStrategies :: WithNamespace . new ( file ...
Load given component files
5,744
def run! mappers = load_mappers relations = load_relations ( mappers ) commands = load_commands ( relations ) container = Container . new ( gateways , relations , mappers , commands ) container . freeze container end
Run the finalization process
5,745
def load_relations ( mappers ) global_plugins = plugins . select { | p | p . relation? || p . schema? } FinalizeRelations . new ( gateways , relation_classes , mappers : mappers , plugins : global_plugins , notifications : notifications ) . run! end
Build entire relation registry from all known relation subclasses
5,746
def new ( relation , new_options = EMPTY_HASH ) self . class . new ( relation , new_options . empty? ? options : options . merge ( new_options ) ) end
Return a new changeset with provided relation
5,747
def register_event ( id , info = EMPTY_HASH ) Notifications . events [ id ] = Event . new ( id , info ) end
Register an event
5,748
def apply_to ( klass , options = EMPTY_HASH ) if mod . respond_to? ( :new ) klass . send ( :include , mod . new ( options ) ) else klass . send ( :include , mod ) end end
Apply this plugin to the provided class
5,749
def project ( * names ) new ( names . map { | name | name . is_a? ( Symbol ) ? self [ name ] : name } ) end
Project a schema to include only specified attributes
5,750
def rename ( mapping ) new_attributes = map do | attr | alias_name = mapping [ attr . name ] alias_name ? attr . aliased ( alias_name ) : attr end new ( new_attributes ) end
Project a schema with renamed attributes
5,751
def wrap ( prefix = name . dataset ) new ( map { | attr | attr . wrapped? ? attr : attr . wrapped ( prefix ) } ) end
Return new schema with all attributes marked as prefixed and wrapped
5,752
def uniq ( & block ) if block new ( attributes . uniq ( & block ) ) else new ( attributes . uniq ( & :name ) ) end end
Return a new schema with uniq attributes
5,753
def finalize_attributes! ( gateway : nil , relations : nil ) inferrer . ( self , gateway ) . each { | key , value | set! ( key , value ) } yield if block_given? initialize_primary_key_names self end
This hook is called when relation is being build during container finalization
5,754
def to_output_hash HASH_SCHEMA . schema ( map { | attr | [ attr . key , attr . to_read_type ] } . to_h ) end
Return coercion function using attribute read types
5,755
def to_input_hash HASH_SCHEMA . schema ( map { | attr | [ attr . name , attr . to_write_type ] } . to_h ) end
Return coercion function using attribute types
5,756
def auto_curry ( name , & block ) arity = instance_method ( name ) . arity return unless public_instance_methods . include? ( name ) && arity != 0 mod = Module . new mod . module_eval do define_method ( name ) do | * args , & mblock | response = if arity < 0 || arity == args . size super ( * args , & mblock ) else self...
Auto - curry a method
5,757
def [] ( * args ) if args . size . equal? ( 1 ) command = super mapper = options [ :mapper ] if mapper command . curry >> mapper else command end else cache . fetch_or_store ( args . hash ) { compiler . ( * args ) } end end
Return a command from the registry
5,758
def relation ( name , options = EMPTY_HASH , & block ) klass_opts = { adapter : default_adapter } . merge ( options ) klass = Relation . build_class ( name , klass_opts ) klass . schema_opts ( dataset : name , relation : name ) klass . class_eval ( & block ) if block register_relation ( klass ) klass end
Relation definition DSL
5,759
def commands ( name , & block ) register_command ( * CommandDSL . new ( name , default_adapter , & block ) . command_classes ) end
Command definition DSL
5,760
def plugin ( adapter , spec , & block ) type , name = spec . flatten ( 1 ) plugin = plugin_registry . send ( type ) . adapter ( adapter ) . fetch ( name ) { plugin_registry . send ( type ) . fetch ( name ) } if block register_plugin ( plugin . configure ( & block ) ) else register_plugin ( plugin ) end end
Configures a plugin for a specific adapter to be enabled for all relations
5,761
def call ( * args , & block ) tuples = if hooks? prepared = if curried? apply_hooks ( before_hooks , * ( curry_args + args ) ) else apply_hooks ( before_hooks , * args ) end result = prepared ? execute ( prepared , & block ) : execute ( & block ) if curried? if args . size > 0 apply_hooks ( after_hooks , result , * arg...
Call the command and return one or many tuples
5,762
def curry ( * args ) if curry_args . empty? && args . first . is_a? ( Graph :: InputEvaluator ) Lazy [ self ] . new ( self , * args ) else self . class . build ( relation , { ** options , curry_args : args } ) end end
Curry this command with provided args
5,763
def map_input_tuples ( tuples , & mapper ) return enum_for ( :with_input_tuples , tuples ) unless mapper if tuples . respond_to? :merge mapper [ tuples ] else tuples . map ( & mapper ) end end
Yields tuples for insertion or return an enumerator
5,764
def apply_hooks ( hooks , tuples , * args ) hooks . reduce ( tuples ) do | a , e | if e . is_a? ( Hash ) hook_meth , hook_args = e . to_a . flatten ( 1 ) __send__ ( hook_meth , a , * args , ** hook_args ) else __send__ ( e , a , * args ) end end end
Apply provided hooks
5,765
def wrap_dataset ( dataset ) if relation . is_a? ( Relation :: Composite ) relation . new ( dataset ) . to_a else dataset end end
Pipes a dataset through command s relation
5,766
def call ( relation ) transformers . reduce ( relation . to_a ) { | a , e | e . call ( a ) } end
Process a relation using the transformers
5,767
def call ( * args ) cache . fetch_or_store ( args . hash ) do type , adapter , ast , plugins , plugins_options , meta = args compiler = with ( id : type , adapter : adapter , plugins : Array ( plugins ) , plugins_options : plugins_options , meta : meta ) graph_opts = compiler . visit ( ast ) command = ROM :: Commands :...
Return a specific command type for a given adapter and relation AST
5,768
def register_command ( rel_name , type , meta , parent_relation = nil ) relation = relations [ rel_name ] type . create_class ( rel_name , type ) do | klass | klass . result ( meta . fetch ( :combine_type , result ) ) if meta [ :combine_type ] setup_associates ( klass , relation , meta , parent_relation ) end plugins ....
Build a command object for a specific relation
5,769
def setup_associates ( klass , relation , meta , parent_relation ) assoc_name = if relation . associations . key? ( parent_relation ) parent_relation else singular_name = Inflector . singularize ( parent_relation ) . to_sym singular_name if relation . associations . key? ( singular_name ) end if assoc_name klass . asso...
Sets up associates plugin for a given command class and relation
5,770
def normalize_gateways ( gateways_config ) gateways_config . each_with_object ( map : { } , gateways : { } ) do | ( name , spec ) , hash | identifier , * args = Array ( spec ) if identifier . is_a? ( Gateway ) gateway = identifier else gateway = Gateway . setup ( identifier , * args . flatten ) end hash [ :map ] [ gate...
Build gateways using the setup interface
5,771
def meta ( opts = nil ) if opts self . class . new ( type . meta ( opts ) , options ) else type . meta end end
Return attribute type with additional meta information
5,772
def inspect opts = options . reject { | k | %i[ type name ] . include? ( k ) } meta_and_opts = meta . merge ( opts ) . map { | k , v | "#{k}=#{v.inspect}" } %(#<#{self.class}[#{type.name}] name=#{name.inspect} #{meta_and_opts.join(' ')}>) end
Return string representation of the attribute type
5,773
def optional sum = self . class . new ( super , options ) read? ? sum . meta ( read : meta [ :read ] . optional ) : sum end
Return nullable attribute
5,774
def each return to_enum unless block_given? if auto_map? mapper . ( dataset . map { | tuple | output_schema [ tuple ] } ) . each { | struct | yield ( struct ) } else dataset . each { | tuple | yield ( output_schema [ tuple ] ) } end end
Yields relation tuples
5,775
def node ( name ) assoc = associations [ name ] other = assoc . node other . eager_load ( assoc ) end
Create a graph node for a given association identifier
5,776
def eager_load ( assoc ) relation = assoc . prepare ( self ) if assoc . override? relation . ( assoc ) else relation . preload_assoc ( assoc ) end end
Return a graph node prepared by the given association
5,777
def new ( dataset , new_opts = EMPTY_HASH ) opts = if new_opts . empty? options elsif new_opts . key? ( :schema ) options . merge ( new_opts ) . reject { | k , _ | k == :input_schema || k == :output_schema } else options . merge ( new_opts ) end self . class . new ( dataset , opts ) end
Return a new relation with provided dataset and additional options
5,778
def with ( opts ) new_options = if opts . key? ( :meta ) opts . merge ( meta : meta . merge ( opts [ :meta ] ) ) else opts end new ( dataset , options . merge ( new_options ) ) end
Returns a new instance with the same dataset but new options
5,779
def map_to ( klass , ** opts ) with ( opts . merge ( auto_map : false , auto_struct : true , meta : { model : klass } ) ) end
Return a new relation that will map its tuples to instances of the provided class
5,780
def apply_to ( schema , options = EMPTY_HASH ) mod . apply ( schema , options ) if mod . respond_to? ( :apply ) end
Apply this plugin to the provided configuration
5,781
def get_construct_args args = [ ] argument_map do | pspec , argument_class , argument_instance | flags = argument_class [ :flags ] if ( flags & ARGUMENT_CONSTRUCT ) != 0 name = pspec [ :name ] . tr ( "-" , "_" ) args << [ name , flags ] end end return args end
not quick! try to call this infrequently
5,782
def set name , value , match_image = nil , flags = 0 gtype = get_typeof name if gtype == IMAGE_TYPE value = Operation :: imageize match_image , value if ( flags & ARGUMENT_MODIFY ) != 0 value = value . copy . copy_memory end elsif gtype == ARRAY_IMAGE_TYPE value = value . map { | x | Operation :: imageize match_image ,...
set an operation argument expanding constants and copying images as required
5,783
def call_enum ( name , other , enum ) if other . is_a? ( Vips :: Image ) Vips :: Operation . call name . to_s , [ self , other , enum ] else Vips :: Operation . call name . to_s + "_const" , [ self , enum , other ] end end
handy for expanding enum operations
5,784
def new_from_image value pixel = ( Vips :: Image . black ( 1 , 1 ) + value ) . cast ( format ) image = pixel . embed 0 , 0 , width , height , extend : :copy image . copy interpretation : interpretation , xres : xres , yres : yres , xoffset : xoffset , yoffset : yoffset end
A new image is created with the same width height format interpretation resolution and offset as self but with every pixel set to the specified value .
5,785
def write_to_memory len = Vips :: SizeStruct . new ptr = Vips :: vips_image_write_to_memory self , len ptr = FFI :: AutoPointer . new ( ptr , GLib :: G_FREE ) ptr . get_bytes 0 , len [ :value ] end
Write this image to a large memory buffer .
5,786
def get_typeof name unless Vips :: at_least_libvips? ( 8 , 5 ) gtype = parent_get_typeof name return gtype if gtype != 0 end Vips :: vips_image_get_typeof self , name end
Get the GType of a metadata field . The result is 0 if no such field exists .
5,787
def get name unless Vips :: at_least_libvips? ( 8 , 5 ) return super if parent_get_typeof ( name ) != 0 end gvalue = GObject :: GValue . alloc result = Vips :: vips_image_get self , name , gvalue raise Vips :: Error if result != 0 gvalue . get end
Get a metadata item from an image . Ruby types are constructed automatically from the GValue if possible .
5,788
def get_fields return [ ] unless Vips . respond_to? :vips_image_get_fields array = Vips :: vips_image_get_fields self names = [ ] p = array until ( q = p . read_pointer ) . null? names << q . read_string GLib :: g_free q p += FFI :: Type :: POINTER . size end GLib :: g_free array names end
Get the names of all fields on an image . Use this to loop over all image metadata .
5,789
def set_type gtype , name , value gvalue = GObject :: GValue . alloc gvalue . init gtype gvalue . set value Vips :: vips_image_set self , name , gvalue end
Create a metadata item on an image of the specifed type . Ruby types are automatically transformed into the matching GType if possible .
5,790
def draw_point ink , left , top , opts = { } draw_rect ink , left , top , 1 , 1 , opts end
Draw a point on an image .
5,791
def - other other . is_a? ( Vips :: Image ) ? subtract ( other ) : linear ( 1 , Image :: smap ( other ) { | x | x * - 1 } ) end
Subtract an image constant or array .
5,792
def / other other . is_a? ( Vips :: Image ) ? divide ( other ) : linear ( Image :: smap ( other ) { | x | 1.0 / x } , 0 ) end
Divide an image constant or array .
5,793
def [] index if index . is_a? Range n = index . size extract_band index . begin , n : n elsif index . is_a? Numeric extract_band index else raise Vips :: Error , "[] index is not range or numeric." end end
Fetch bands using a number or a range
5,794
def to_a memory = write_to_memory template = { :char => 'c' , :uchar => 'C' , :short => 's_' , :ushort => 'S_' , :int => 'i_' , :uint => 'I_' , :float => 'f' , :double => 'd' , :complex => 'f' , :dpcomplex => 'd' } [ format ] + '*' array = memory . unpack ( template ) pixel_array = array . each_slice ( bands ) . to_a r...
Convert to an Array . This will be slow for large images .
5,795
def bandjoin other unless other . is_a? Array other = [ other ] end not_all_real = ! other . all? { | x | x . is_a? Numeric } if not_all_real Vips :: Image . bandjoin ( [ self ] + other ) else bandjoin_const other end end
Join a set of images bandwise .
5,796
def composite overlay , mode , opts = { } unless overlay . is_a? Array overlay = [ overlay ] end unless mode . is_a? Array mode = [ mode ] end mode = mode . map do | x | GObject :: GValue . from_nick Vips :: BLEND_MODE_TYPE , x end Vips :: Image . composite ( [ self ] + overlay , mode , opts ) end
Composite a set of images with a set of blend modes .
5,797
def maxpos v , opts = max x : true , y : true x = opts [ 'x' ] y = opts [ 'y' ] return v , x , y end
Return the coordinates of the image maximum .
5,798
def minpos v , opts = min x : true , y : true x = opts [ 'x' ] y = opts [ 'y' ] return v , x , y end
Return the coordinates of the image minimum .
5,799
def get_pspec name pspec = GObject :: GParamSpecPtr . new argument_class = Vips :: ArgumentClassPtr . new argument_instance = Vips :: ArgumentInstancePtr . new result = Vips :: vips_object_get_argument self , name , pspec , argument_class , argument_instance return nil if result != 0 pspec end
return a pspec or nil ... nil wil leave a message in the error log which you must clear