Sha256: 4ebfafa6bbe32e6f6ad9cb9730b8ff0909e411efe5e52b8993c16836a9b6326e

Contents?: true

Size: 1.5 KB

Versions: 24

Compression:

Stored size: 1.5 KB

Contents

#!/usr/bin/env ruby

$-w = true
$:.unshift File.dirname($0) + '/../lib'

require 'pp'
require 'getoptlong'
require 'vpim/vcard'

HELP =<<EOF
Usage: #{$0} <vcard>...

Options
  -h,--help      Print this helpful message.
  -n,--name      Print the vCard name.
  -d,--debug     Print debug information.

Examples:
EOF

opt_name  = nil
opt_debug = nil

opts = GetoptLong.new(
  [ "--help",    "-h",              GetoptLong::NO_ARGUMENT ],
  [ "--name",    "-n",              GetoptLong::NO_ARGUMENT ],
  [ "--debug",   "-d",              GetoptLong::NO_ARGUMENT ]
)

opts.each do |opt, arg|
  case opt
    when "--help" then
      puts HELP
      exit 0

    when "--name" then
      opt_name = true

    when "--debug" then
      opt_debug = true
  end
end

if ARGV.length < 1
  puts "no vcard files specified, try -h!"
  exit 1
end

ARGV.each do |file|

  cards = Vpim::Vcard.decode(open(file))

  cards.each do |card|
    card.each do |field|
      puts "..#{field.name.capitalize}=#{field.value.inspect}"

      if field.group
        puts " group=#{field.group}"
      end

      field.each_param do |param, values|
        puts " #{param}=[#{values.join(", ")}]"
      end
    end

    if opt_name
      begin
      puts "#name=#{card.name.formatted}"
      rescue
        puts "! failed to decode name!"
      end
    end


    if opt_debug
      card.groups.sort.each do |group|
        card.enum_by_group(group).each do |field|
          puts "#{group} -> #{field.inspect}"
        end
      end
    end

    puts ""
  end
end

Version data entries

24 entries across 24 versions & 11 rubygems

Version Path
vpim-24.2.20 samples/vcf-dump.rb
fraser-vpim-0.658 samples/vcf-dump.rb
fraser-vpim-0.659 samples/vcf-dump.rb
fraser-vpim-rails-0.658 samples/vcf-dump.rb
fraser-vpim-rails-0.659 samples/vcf-dump.rb
xing-vpim-0.658.1 samples/vcf-dump.rb
vpim-13.11.11 samples/vcf-dump.rb
vpim2-0.0.1 samples/vcf-dump.rb
vpim-rails-reinteractive-0.7 samples/vcf-dump.rb
vpim-rails-0.665 samples/vcf-dump.rb
thoughtafter-vpim-0.7.0.1 samples/vcf-dump.rb
vpim-rails-0.664 samples/vcf-dump.rb
vpim-rails-0.663 samples/vcf-dump.rb
vpim-rails-0.662 samples/vcf-dump.rb
scashin133-vpim-9.4.0 samples/vcf-dump.rb
vpim-rails-0.661 samples/vcf-dump.rb
mumboe-vpim-0.7 samples/vcf-dump.rb
mumboe-vpim-0.695 samples/vcf-dump.rb
fairtilizer-vpim-0.695 samples/vcf-dump.rb
vpim-0.604 samples/vcf-dump.rb