<commit_before># -*- coding: utf-8 -*-
framework 'Foundation'

module Salut

# Advertises its service on the local network using Bonjour.
class Service

  # @return [String] service_type
  attr_accessor :service_type

  # @return [String] instance_name
  attr_accessor :instance_name

  # @return [Fixnum] port
  attr_accessor :port

  # @return [NSNetService]
  attr_reader :service

  # @return [Hash{Symbol=>Proc}]
  attr_accessor :delegates

  # @param [Symbol] key
  # @return [Proc]
  def [] key
    @delegates[key]
  end

  # @param [Symbol] key
  # @param [Proc] value
  # @return [Proc]
  def []= key, value
    @delegates[key] = value
  end

  # @example Initializing with properties
  #  service = Advertiser.new({
  #    service_type:'_http._tcp.',
  #    instance_name:'Test',
  #    port:3000
  #  })
  # @param [Hash{Symbol=>String,Fixnum}] params key-value pairs specifying the
  #  type, name, and port for the service
  def initialize params = {}
    @service_type  = params[:service_type]
    @instance_name = params[:instance_name]
    @port          = params[:port]
    @delegates     = {}
  end

  # Create a new NSNetService instance and publish to the local network.
  # @return [NSNetService] the service that began advertising
  def start_advertising domain_name = ''
    @service = NSNetService.alloc.initWithDomain domain_name,
                                            type:@service_type,
                                            name:@instance_name,
                                            port:@port
    @service.delegate = self
    @service.publish
  end

  # @param [Float] timeout number of seconds to wait before timing out
  def resolve timeout = 60.0
    @service.resolveWithTimeout timeout
  end

  # @return [NSNetService] the service that just stopped advertising
  def stop_advertising
    @service.stop
    @service = nil
  end


  ### delegate methods

  # @yieldparam [NSNetService] sender
  # @return [nil]<commit_msg>Allow initialization of Service with NSNetService objects<commit_after># -*- coding: utf-8 -*-
framework 'Foundation'

module Salut

# Advertises its service on the local network using Bonjour.
class Service

  # @return [String] service_type
  attr_accessor :service_type

  # @return [String] instance_name
  attr_accessor :instance_name

  # @return [Fixnum] port
  attr_accessor :port

  # @return [NSNetService]
  attr_reader :service

  # @return [Hash{Symbol=>Proc}]
  attr_accessor :delegates

  # @param [Symbol] key
  # @return [Proc]
  def [] key
    @delegates[key]
  end

  # @param [Symbol] key
  # @param [Proc] value
  # @return [Proc]
  def []= key, value
    @delegates[key] = value
  end

  # @example Initializing with properties
  #  service = Advertiser.new({
  #    service_type:'_http._tcp.',
  #    instance_name:'Test',
  #    port:3000
  #  })
  # @example Initializing with an existing service
  #  service = Advertiser.new({
  #    service:NSNetService.alloc.initWithDomain('',
  #                                         type:'_http._tcp.',
  #                                         name:`hostname -s`.chomp,
  #                                         port:3000)
  #  })
  # @param [Hash{Symbol=>String,Fixnum}] params key-value pairs specifying the
  #  type, name, and port for the service
  def initialize params = {}
    @service_type  = params[:service_type]
    @instance_name = params[:instance_name]
    @port          = params[:port]
    @service       = params[:service]
    @delegates     = {}
  end

  # Create a new NSNetService instance and publish to the local network.
  # @return [NSNetService] the service that began advertising
  def start_advertising domain_name = ''
    @service = NSNetService.alloc.initWithDomain domain_name,
                                            type:@service_type,
                                            name:@instance_name,
                                            port:@port
    @service.delegate = self
    @service.publish
  end

  # @param [Float] timeout number of seconds to wait before timing out
  def resolve timeout = 60.0
    @service.resolveWithTimeout timeout
  end

  # @return [NSNetService] the service that just stopped advertising
  def stop_advertising
    @service.stop
    @service = nil
  end


  ### delegate methods

  # @yieldparam [NSNetService] sender
  # @return [nil]
{'fraction_non_alphanumeric': 0.09681119522826337, 'fraction_numerical': 0.004588208304657031, 'mean_word_length': 2.4548335974643423, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1141466', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1239, 'n_words': 356}