Class: Teams::Api::CitationAppearance

Inherits:
Model
  • Object
show all
Defined in:
lib/teams/api/citation_appearance.rb

Constant Summary collapse

ADAPTIVE_CARD_CONTENT_TYPE =
"application/vnd.microsoft.card.adaptive"

Instance Attribute Summary

Attributes inherited from Model

#raw

Instance Method Summary collapse

Constructor Details

#initialize(raw = nil, name: nil, text: nil, url: nil, abstract: nil, icon: nil, keywords: nil, usage_info: nil) ⇒ CitationAppearance

Returns a new instance of CitationAppearance.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/teams/api/citation_appearance.rb', line 8

def initialize(raw = nil, name: nil, text: nil, url: nil, abstract: nil, icon: nil, keywords: nil, usage_info: nil)
  body = raw || {}
  body = body.to_h if body.respond_to?(:to_h)
  body = body.merge({
    "name" => name,
    "text" => text,
    "url" => url,
    "abstract" => abstract,
    "icon" => icon,
    "keywords" => keywords,
    "usageInfo" => usage_info
  }.compact)
  super(body)
end

Instance Method Details

#abstractObject



35
36
37
# File 'lib/teams/api/citation_appearance.rb', line 35

def abstract
  read("abstract")
end

#iconObject



39
40
41
# File 'lib/teams/api/citation_appearance.rb', line 39

def icon
  read("icon")
end

#keywordsObject



43
44
45
# File 'lib/teams/api/citation_appearance.rb', line 43

def keywords
  read("keywords")
end

#nameObject



23
24
25
# File 'lib/teams/api/citation_appearance.rb', line 23

def name
  read("name")
end

#textObject



27
28
29
# File 'lib/teams/api/citation_appearance.rb', line 27

def text
  read("text")
end

#to_hObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/teams/api/citation_appearance.rb', line 51

def to_h
  validate!

  body = {
    "@type" => "DigitalDocument",
    "name" => name,
    "abstract" => abstract
  }
  body["text"] = text if text
  body["url"] = url if url
  body["encodingFormat"] = ADAPTIVE_CARD_CONTENT_TYPE if text && !text.empty?
  body["image"] = { "@type" => "ImageObject", "name" => icon } if icon
  body["keywords"] = keywords if keywords
  body["usageInfo"] = usage_info.to_h if usage_info && usage_info.respond_to?(:to_h)
  body["usageInfo"] = usage_info if usage_info && !usage_info.respond_to?(:to_h)
  body
end

#urlObject



31
32
33
# File 'lib/teams/api/citation_appearance.rb', line 31

def url
  read("url")
end

#usage_infoObject



47
48
49
# File 'lib/teams/api/citation_appearance.rb', line 47

def usage_info
  read("usageInfo", "usage_info")
end