Class: Wikisnakker::Snak
- Inherits:
-
Object
- Object
- Wikisnakker::Snak
- Defined in:
- lib/wikisnakker/snak.rb
Instance Method Summary collapse
-
#initialize(snak) ⇒ Snak
constructor
A new instance of Snak.
- #value ⇒ Object
Constructor Details
#initialize(snak) ⇒ Snak
Returns a new instance of Snak.
5 6 7 |
# File 'lib/wikisnakker/snak.rb', line 5 def initialize(snak) @snak = snak end |
Instance Method Details
#value ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wikisnakker/snak.rb', line 11 def value return if %w(somevalue novalue).include?(@snak[:snaktype]) case @snak[:datatype] when 'commonsMedia' # https://commons.wikimedia.org/wiki/Commons:FAQ#What_are_the_strangely_named_components_in_file_paths.3F # commons = 'https://commons.wikimedia.org/wiki/File:%s' % @snak["datavalue"]["value"] val = @snak[:datavalue][:value].tr(' ', '_') md5 = Digest::MD5.hexdigest val "https://upload.wikimedia.org/wikipedia/commons/#{md5[0]}/#{md5[0..1]}/#{val}" when 'wikibase-item' # "Q%s" % @snak["datavalue"]["value"]["numeric-id"] Item.new(@snak[:datavalue][:value]) when 'string' @snak[:datavalue][:value] when 'external-id' @snak[:datavalue][:value] when 'quantity' if @snak[:datavalue][:value][:upperBound] == @snak[:datavalue][:value][:lowerBound] @snak[:datavalue][:value][:amount].to_i else warn "FIXME: Unhandled 'quantity': #{@snak[:datavalue][:value]}" end when 'time' case @snak[:datavalue][:value][:precision] when 11 @snak[:datavalue][:value][:time][1..10] when 10 @snak[:datavalue][:value][:time][1..7] when 9 @snak[:datavalue][:value][:time][1..4] when 7 '' # Just ignore dates with century precision else warn "FIXME: Unhandled 'time' precision: #{@snak[:datavalue][:value][:precision]}" end when 'url' @snak[:datavalue][:value] else warn "FIXME: '#{@snak[:datatype]}' is not implemented yet in Wikisnakker::Snak#value. Defaulting to empty string. #{@snak[:datavalue][:value]}" '' end end |