<commit_before>require 'osx/cocoa'
require 'mac-network'

OSX.require_framework('SystemConfiguration')

class Mac::Network::Interface
  attr_reader :sc_interface_ref

  def self.store
    @@store ||= OSX::SCDynamicStoreCreate(nil, "mac-network", nil, nil)
  end

  def self.all
    OSX::SCNetworkInterfaceCopyAll().map {|l| self.create(l) }.reject {|i| i.name.to_s =~ /BlueTooth/i }
  end

  def self.all_with_link
    self.all.select {|i| i.has_link? }
  end

  def self.all_wired
    self.all.select {|i| i.wired? }
  end

  def self.all_wireless
    self.all.select {|i| !i.wired? }
  end

  def self.first
    all.first
  end

  def self.find_by_name(interface_name)
    all.select {|i| i.name == interface_name }.first
  end

  def initialize(sc_interface_ref)
    @sc_interface_ref = sc_interface_ref
  end

  def self.create(*args)
    self.new(*args)
  end

  def bsd_name
    OSX::SCNetworkInterfaceGetBSDName(self.sc_interface_ref)
  end

  def name
    OSX::SCNetworkInterfaceGetLocalizedDisplayName(self.sc_interface_ref).to_s
  end

  def wired?
    !!(name =~ /Ethernet/)
  end

  def inspect
    "#{self.class.name}: name => #{name}, bsd_name => #{bsd_name}"
  end

  def has_link?
    !!(OSX::SCDynamicStoreCopyValue(self.class.store, "State:/Network/Interface/#{bsd_name}/Link").fetch("Active") == 1)
  end

end<commit_msg>add has_ip? to Interface<commit_after>require 'osx/cocoa'
require 'mac-network'

OSX.require_framework('SystemConfiguration')

class Mac::Network::Interface
  attr_reader :sc_interface_ref

  def self.store
    @@store ||= OSX::SCDynamicStoreCreate(nil, "mac-network", nil, nil)
  end

  def self.all
    OSX::SCNetworkInterfaceCopyAll().map {|l| self.create(l) }.reject {|i| i.name.to_s =~ /BlueTooth/i }
  end

  def self.all_with_link
    self.all.select {|i| i.has_link? }
  end

  def self.all_wired
    self.all.select {|i| i.wired? }
  end

  def self.all_wireless
    self.all.select {|i| !i.wired? }
  end

  def self.first
    all.first
  end

  def self.find_by_name(interface_name)
    all.select {|i| i.name == interface_name }.first
  end

  def initialize(sc_interface_ref)
    @sc_interface_ref = sc_interface_ref
  end

  def self.create(*args)
    self.new(*args)
  end

  def bsd_name
    OSX::SCNetworkInterfaceGetBSDName(self.sc_interface_ref)
  end

  def name
    OSX::SCNetworkInterfaceGetLocalizedDisplayName(self.sc_interface_ref).to_s
  end

  def wired?
    !!(name =~ /Ethernet/)
  end

  def inspect
    "#{self.class.name}: name => #{name}, bsd_name => #{bsd_name}"
  end

  def has_link?
    !!(OSX::SCDynamicStoreCopyValue(self.class.store, "State:/Network/Interface/#{bsd_name}/Link").fetch("Active") == 1)
  end

  def has_ip?
    !!(OSX::SCDynamicStoreCopyValue(self.class.store, "State:/Network/Interface/#{bsd_name}/IPv4"))
  end

end
{'fraction_non_alphanumeric': 0.13691322901849218, 'fraction_numerical': 0.0010668563300142249, 'mean_word_length': 3.7677966101694915, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1656357', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1054, 'n_words': 195}