Class: ScribeDb::Model::Scribe

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/scribelite/models/scribe.rb,
lib/scribelite/models/forward.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.avifObject



23
# File 'lib/scribelite/models/scribe.rb', line 23

def self.avif() where( content_type: 'image/avif' ); end

.content_type_countsObject Also known as: counts_by_content_type



96
97
98
99
# File 'lib/scribelite/models/scribe.rb', line 96

def self.content_type_counts
    group( 'content_type' )
    .order( Arel.sql( 'COUNT(*) DESC, content_type')).count
end

.gifObject



19
# File 'lib/scribelite/models/scribe.rb', line 19

def self.gif() where( content_type: 'image/gif' ); end

.htmlObject



41
42
43
44
45
46
# File 'lib/scribelite/models/scribe.rb', line 41

def self.html
    where( content_type: [
       'text/html;charset=utf-8',
       'text/html',
      ])
end

.imageObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/scribelite/models/scribe.rb', line 29

def self.image  
     ## change to/or add alias e.g. image/images - why? why not
    where( content_type: [
        'image/png',
        'image/jpeg',
        'image/gif',
        'image/webp',
        'image/svg+xml',
        'image/avif',
        ])
end

.jpgObject Also known as: jpeg



20
# File 'lib/scribelite/models/scribe.rb', line 20

def self.jpg() where( content_type: 'image/jpeg' ); end

.jsObject Also known as: javascript



48
49
50
51
52
53
# File 'lib/scribelite/models/scribe.rb', line 48

def self.js
    where( content_type: [
       'text/javascript',
       'application/javascript',
      ])
end

.largestObject Also known as: biggest



92
93
94
# File 'lib/scribelite/models/scribe.rb', line 92

def self.largest
   order( 'bytes DESC' )
end

.pngObject

scope like helpers



18
# File 'lib/scribelite/models/scribe.rb', line 18

def self.png() where( content_type: 'image/png' ); end

.sub100kObject



84
# File 'lib/scribelite/models/scribe.rb', line 84

def self.sub100k()  where( 'num < 100000' ); end

.sub10kObject



82
# File 'lib/scribelite/models/scribe.rb', line 82

def self.sub10k()  where( 'num < 10000' ); end

.sub10mObject



87
# File 'lib/scribelite/models/scribe.rb', line 87

def self.sub10m()  where( 'num < 10000000' ); end

.sub1kObject

def self.search( q ) ## “full-text” search helper

    ##  rename to text_search - why? why not?        
    ## auto-sort by num - why? why not?
    joins(:blob).text.where( "content LIKE '%#{q}%'" ).order('num')
end


80
# File 'lib/scribelite/models/scribe.rb', line 80

def self.sub1k()  where( 'num < 1000' ); end

.sub1mObject



85
# File 'lib/scribelite/models/scribe.rb', line 85

def self.sub1m()  where( 'num < 1000000' ); end

.sub20kObject



83
# File 'lib/scribelite/models/scribe.rb', line 83

def self.sub20k()  where( 'num < 20000' ); end

.sub20mObject



88
# File 'lib/scribelite/models/scribe.rb', line 88

def self.sub20m()  where( 'num < 20000000' ); end

.sub21mObject



89
# File 'lib/scribelite/models/scribe.rb', line 89

def self.sub21m()  where( 'num < 21000000' ); end

.sub2kObject



81
# File 'lib/scribelite/models/scribe.rb', line 81

def self.sub2k()  where( 'num < 2000' ); end

.sub2mObject



86
# File 'lib/scribelite/models/scribe.rb', line 86

def self.sub2m()  where( 'num < 2000000' ); end

.svgObject



22
# File 'lib/scribelite/models/scribe.rb', line 22

def self.svg()  where( content_type: 'image/svg+xml' ); end

.textObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/scribelite/models/scribe.rb', line 59

def self.text
    ## change to/or add alias e.g. text/texts - why? why not
    ## include html or svg in text-only inscription - why? why not?
    ##  include markdown in text-only inscription - why? why not?
    ##   make content_type lower case with lower() - why? why not?
    where( content_type: [
              'text/plain',
              'text/plain;charset=utf-8',
              'text/plain;charset=us-ascii',
              'application/json',
         ])
end

.webpObject



21
# File 'lib/scribelite/models/scribe.rb', line 21

def self.webp() where( content_type: 'image/webp' ); end

Instance Method Details

#extnameObject

instance methods



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/scribelite/models/scribe.rb', line 108

def extname
  ## map mime type to file extname
  ## see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
  ##  for real-world usage, see https://dune.com/dgtl_assets/bitcoin-ordinals-analysis
  ##  https://github.com/casey/ord/blob/master/src/media.rs

   if content_type.start_with?( 'text/plain' )
      '.txt'
   elsif content_type.start_with?( 'text/markdown' )
      '.md'
   elsif content_type.start_with?( 'text/html' )
      '.html'
   elsif content_type.start_with?( 'text/javascript' ) ||
         content_type.start_with?( 'application/javascript' )
      ## note: application/javascript is considered bad practice/legacy
      '.js'
   elsif content_type.start_with?( 'image/png' )
       ## Portable Network Graphics (PNG)
      '.png'
   elsif content_type.start_with?( 'image/jpeg' )
        ##  Joint Photographic Expert Group image (JPEG) 
       '.jpg'   ## use jpeg - why? why not?
   elsif content_type.start_with?( 'image/webp' )
        ## Web Picture format (WEBP)
       '.webp'   ## note: no three-letter extension available
   elsif content_type.start_with?( 'image/svg' )
        ## Scalable Vector Graphics (SVG) 
       '.svg'
   elsif content_type.start_with?( 'image/gif' ) 
       ##  Graphics Interchange Format (GIF)
       '.gif'
   elsif content_type.start_with?( 'image/avif' )  
       ## AV1 Image File Format (AVIF)
       '.avif'
   elsif content_type.start_with?( 'application/epub' )
       '.epub'
   elsif content_type.start_with?( 'application/pdf' )
       '.pdf'
   elsif content_type.start_with?( 'application/json' )
       '.json'
   elsif content_type.start_with?( 'application/pgp-signature' )
       '.sig'
   elsif content_type.start_with?( 'audio/mpeg' )
       '.mp3'
   elsif content_type.start_with?( 'audio/midi' )
       '.midi'
   elsif content_type.start_with?( 'video/mp4' )
       '.mp4'
   elsif content_type.start_with?( 'video/webm' )
       '.wepm'
   elsif content_type.start_with?( 'audio/mod' )  
      ## is typo? possible? only one inscription in 20m?
       '.mod'   ## check/todo/fix if is .wav?? 
   else
      puts "!! ERROR - no file extension configured for content type >#{content_type}<; sorry:"
      pp self
      exit 1
   end
end